Operation With Strings

May 6, 2014

I have to write a java programm,where i have given string. Output should be like that:

1. print only once what characters are apearinng in string, and the last index of it

2. print how many characters are in the string

I have to do it only with loops,no special classes

So far:

public static void main( String[] args ) {
String besedilo = "Testiranje";
besedilo = besedilo.toLowerCase();
for (int i=0; i<besedilo.length();i++)

[code]...

View Replies


ADVERTISEMENT

How To Find Whether Strings Contained In Array Of Strings Constitute A Similar Character Or Not

Aug 25, 2014

I am having an array of strings and i want to find out whether these strings contained in the array contain a similar character or not.For example i am having following strings in the array of string:

aadafbd
dsfgdfbvc
sdfgyub
fhjgbjhjd

my program should provide following result: 3 because i have 3 characters which are similar in all the strings of the array(f,b,d).

View Replies View Related

Sorting Lowercase Strings Before Uppercase Strings

Mar 26, 2014

I can sort strings in a collection by uppercase and then lowercase though I was wondering if there is any way of doing it in reverse, sorting by lowercase then by uppercase.

View Replies View Related

Mathematical Operation On Bytes

Jan 28, 2015

byte a1 = 0;
byte a2 = 4
byte a3 = 4;

//below statement gives a compilation error
a1 = a2 + a3;

//below line compiles fine.
a1 = 4 + 4;

View Replies View Related

String To Math Operation

Sep 14, 2014

Given a string of numbers and operator. Compute as follows:

Consider, "000293000002030403+0400293059694" is the input.

a. Separate the two operands and one operator:
"000293000002030403" "+" "0400293059694"

b. On each string operand, take each digit. ADD them all.
(2+9+3+2+3+4+3) + (4+2+9+3+5+9+6+9+4)
The two string operands should now become two integers.

c. Lastly, perform the operation using the string operator specified on the original string.
26 + 51 = 77

I don't know why I get the sum of 52 when I use a for loop.

Here are my codes:

public class string2math {
public static void main(String[] args) {
String input = "000293000002030403+0400293059694";
String [] operand = input.split("+");
String firstOpera = operand[0];

[Code] ...

View Replies View Related

Addition Operation On Character Variables

Feb 8, 2015

When addition operation is performed on the character variables ,then it specifies actually that the ASCII values are added because the character variable stores ASCII value of the character constant ,then why after the addition the result cannot be stored inside a character variable ,why it needs to be stored in an integer variable only ,when actually the character variable stores the ASCII value then why is it an error to store the added result in an character variable.

View Replies View Related

Swing/AWT/SWT :: JDialog Close Operation

Mar 4, 2011

how the entire application could be close when you click on X in a JDialog Box. I have tried

System.Exit (0)

but it only close the Dialog box

View Replies View Related

Using Queues To Simulate Airport Operation

Nov 13, 2014

*Write a program to simulate this airport's operation. You might assume a simulated clock that advances in one-minute intervals. For each minute, generate two random numbers: If the first in less than LandingTime /60, a "landing arrival" has occurred and is added to the landing queue, and if the second is less than TakeOffTime /60, a "takeoff arrival" has occurred and is added to the takeoff queue*.

*Next, check whether the runway is free. If it is, first check whether the landing queue is nonempty, and if so, allow the first plane to land; otherwise, consider the takeoff queue. Have the program calculate the average queue length and the average time that an airplane spends in a queue.*

I have most of the code done as you can see below:

* Queue Interface: Queue.java
* Queue Implementation: ArrayQueue.java
* Demo Program: Airport.java

Right now, I am stuck on the first calculation which is trying to figure out the average size of the landing queue. For some reason, as you can see at the bottom of my demo program, the average always comes out to be 0.0 and I'm not sure what's wrong.

Secondly, how to calculate the average time a plane stays inside a queue for. Write a program to simulate this airport's operation. You might assume a simulated clock that advances in one-minute intervals. For each minute, generate two random numbers: If the first in less than LandingTime /60, a "landing arrival" has occurred and is added to the landing queue, and if the second is less than TakeOffTime /60, a "takeoff arrival" has occurred and is added to the takeoff queue.

Next, check whether the runway is free. If it is, first check whether the landing queue is nonempty, and if so, allow the first plane to land; otherwise, consider the takeoff queue. Have the program calculate the average queue length and the average time that an airplane spends in a queue.

I have most of the code done as you can see below:

* Queue Interface: Queue.java
* Queue Implementation: ArrayQueue.java
* Demo Program: Airport.java

Right now, I am stuck on the first calculation which is trying to figure out the average size of the landing queue. For some reason, as you can see at the bottom of my demo program, the average always comes out to be 0.0 and I'm not sure what's wrong.

Secondly, how to calculate the average time a plane stays inside a queue for.

View Replies View Related

Recursion - If Else Loop To Check If Operation Is Completed

Feb 2, 2014

I am currently learning recursion, and i have a query. I have a program that receives user input, and outputs the decimal input into binary form. In my recursive function, I have a if else loop to check if operation is completed.

public static int Converter(int input, int weight) {
System.out.printf("Input is now %d, weight is now %d
",input,weight);
if(input==0) {
return 0;

[Code] .....

The final return, when input finally hits zero is concatenating 0 to whatever i have this far. e.g. Decimal 10 should give 1010, but because of the "return 0", instead of getting 1010+0, i am getting 10100.

I can solve the problem by creating a variable sum,and passing along, but i am just curious why the final return 0 is giving me not a +0, but a concatenate 0.

View Replies View Related

How To Perform Row Operation - Store Data Into 2D Matrix

Sep 18, 2014

I am able to perform column operation but not able to perform row operation because i am not able to store data say a 2 matrix [][]. I need to store the data into a 2-D matrix. Here is my code:

Java Code:

import java.awt.List;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Scanner;
public class colRowRead {

[Code] ....

I tried something like that:

for(int i=0; i<rows; i++) {
for(int j=0; j<cols; j++){
matrix [i][j]=textFile.get(i).split(" ");
//System.out.println(matrix[i][j]);
}
}
*/ mh_sh_highlight_all('java');

File col.txt is like this:

Java Code:
5 9 7 1 5
3 6 8 6 8
4 6 7 8 9
9 8 3 5 7 mh_sh_highlight_all('java');

View Replies View Related

Program To Simulate Operation Of Simple Robot

Apr 26, 2015

Write a program to simulate the operation of a simple robot. The robot moves in four directions: Forward, backwawrd, left, and right. The job of the robot is to move items and place it in the right slots in each station. There are 8 stations plus the pickup station. Pick up station is the initial start where the robot picks the items. 8 items can be placed on each station. The nearest station must be filled before placing items on the next station. The items are marked with identification or serial numbers. The items with odd serial number go to the right and items with even number go to the eft. The last slot, number 7 is reserved for light items which are less than 80kg. The serial number is a five digit number, the MSB digit 5 indicates that the product must be placed in the fifth station which is keeping the product at 20 degree F.

View Replies View Related

Invalid Operation At Current Cursor Position

Sep 30, 2014

I have now slowly moving on the learning Database Connectivity.Found a simple example on one site and tried to execute it, Creating a database, connecting to it and displaying the output.

I am getting trouble with recordset in displaying all the records in the badabase. It displays the very first record correctly but if I try to enclose it in while(rs.next()) loop, it generates an error message saying "Invalid operation at current cursor position".

package database_console;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.ResultSet;

[code]....

View Replies View Related

Arithmetic Operation - String Index Out Of Range Error?

Nov 17, 2014

I am trying to write a program which asks the user to enter two numbers and then do the arithmetic operation based on user's input . No compiling errors but when I run the program I keep getting "StringIndexOutOfBounds" error .
 
class arithmetic { 
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int ent1 = 0;

[Code]....

View Replies View Related

Servlets :: Clean Way To Log Every Database Operation Issued By Which User

May 16, 2014

So, there's a new requirement to log which user issues what database operations. The dumb way is to pass the session object around, but I hope said dumb way is not the only way to achieve this. Hopefully there's another cleaner and smarter way to do this.

View Replies View Related

Live Bytes For Object Instance In JVisualVM Increase On Every Operation

May 5, 2014

Whenever i perform any operation in my application Live Bytes of a particular Instance of a class increases by 1000.Although i perform the same operation everytime it always increases by 100 or 1000.Is this a memory leak or does these instances increase everytime we perform an operation.

View Replies View Related

Read Text File And Perform Operation On Specific Columns

Dec 9, 2011

I am somewhat of a java newbie (learned it awhile back and just getting back to programming some again.) I have a text file of data much larger than this, but here are the first ten rows and first 10 columns.

39755320111041730140.633038085-2.117082366149.069997
39850320111041730150.633038085-2.117082511148.309997
39955320111041730160.633037998-2.117082293149.509997
40055320111041730170.633037945-2.117082351149.239997
.......

I can read and write all the data back out to files. But I am not sure about a few things.

First would it be best to use BufferedReader and OutputStream such as:

public static void main(String[] args) throws IOException {
BufferedReader bReader = new BufferedReader(new FileReader ("testdata.txt"));
BufferedOutputStream bytesOut = new BufferedOutputStream(new FileOutputStream ("outfile.txt"));

Second, I was then going to initialize an array but I might have 30 or more columns of data, of which I might perform and output only 10 columns to my output.txt file so is this a good way?

Third, I only want to perform operations (such as average the data, convert units or multiply two columns together) on 10 of the 30 plus columns and print out results to output.txt file. For example, In testdata.txt file above, I want to skip first seven columns. I then want to take column 8 and multiply by 100 then divide by 3 and output result to output file. I want to do same for column 9. Column 10 I want to multiply by different number (by 3.5).

View Replies View Related

Program That Implement Final Method And Perform Arithmetic Operation

Mar 4, 2014

class A
{
public final int Add(int a,int b) {
return a+b;
}
}

class B
{
public static void main (String args[])
{
System.out.println(Model.Add(5,10));
}
}

This is what I have. I'm not sure if this even makes use of a final method. But when I run it I get an error saying cannot find symbol for line 13.

View Replies View Related

Java Date Function Minus Operation Excluding Weekends And Holidays

Feb 12, 2014

I have deduct a number of days excluding holiday and weekends .So if I have to deduct 4 days from current day (02/12) and assuming 02/10 is a holiday my answer will be 02/05

Now below is the code I have come up with however its not working with the hardcoded dates I am passing in to the Holiday Calendar String .Only the last value is considered . How I should store this values and compare with the date

package date_calculation;

/**
* Returns a tick for each of
* the dates as represented by the <code>dtConstants</code> or the list of <code>dtDateTimes</code>
* occurring in the period as represented by begin -> end.
*

[Code]...

View Replies View Related

EJB / EE :: Entity And Mapped Superclass Throw Error - Has No Table In Database But Operation Requires It

Apr 16, 2014

I have a superclass used for all the other entity

@MappedSuperclass
public abstract class BssStandardEntityLaravel extends BssStandardEntity
implements InterfacciaBssStandardEntity, Cloneable{
private static final long serialVersionUID = 1L;
@Column(name = "created_at", nullable=true)
@Temporal(TemporalType.TIMESTAMP)
protected Date created_at = new Date();

[Code] ....

When i try to read some data with a JPA controller, this error is raised:

Persistent class "com.bss.libbssabstract.database.entity.BssStandardEntityLaravel" has no table in the database, but the operation requires it. Please check the specification of the MetaData for this class.
org.datanucleus.store.rdbms.exceptions.NoTableManagedException: Persistent class "com.bss.libbssabstract.database.entity.BssStandardEntityLaravel" has no table in the database, but the operation requires it. Please check the specification of the MetaData for this class.
at org.datanucleus.store.rdbms.RDBMSStoreManager.getDatastoreClass(RDBMSStoreManager.java:702)

[Code] ....

It requires BssStandardEntityLaravel table like a normal entity. I used the same entity package in other applications and it works perfectly. Why this error is raised?

I use jpa2.1.0 and datanucleus to enhance classes

View Replies View Related

Web Services :: Difference Between Web-service And Service Operation?

Feb 24, 2015

difference between webservice and service operation.

View Replies View Related

How To Compare Strings

Mar 13, 2014

Its supposed to notify the user if they have a palindrome, but keeps returning true even when I type, "hello".

import java.util.Scanner;
public class PalinDrome {
public static void main(String[] args) {
String line;
Scanner input = new Scanner(System.in);
System.out.print("Please enter a word ");

[code]....

View Replies View Related

Reading Only First Name From Strings?

Feb 12, 2014

I know that in c++ in order to read a string like

PHP Code:

. you need to use

getline(cin,string variable)

. In java, I have noticed that using

String name=keyboard.nextLine()

automatically reads the whole line...Suppose I wanted to read the first name only, how would I be able to accomplish that?

View Replies View Related

Extracting The Strings?

Jul 3, 2014

example input (#federer #great #game )->
output : [federer] [great][game], [federer, game],[federer,great], [game,great], [federer, game,great]

View Replies View Related

Top Three Strings In Array

May 18, 2015

I need my code to print out the top three most common IP Addresses in the ArrayList. Right now I have it printing out the top IP Address. I am a little confused as to how to get it to print out three. Every time I change something, It doesn't give me the correct results

My Code:
public class Log_File_Analysis {
private static ArrayList<String> ipAddress = new ArrayList<>();
private static String temp , mostCommon;
static int max = 0;
static int num = 0;

[Code] .....

View Replies View Related

Pass By Value And Strings

Jul 19, 2014

Below is the snippet of code

public static void main(String[] args) throws Exception {
String s = "oldString";
reverse(s);
System.out.println(s); // oldString
}
public static void modifyString(String s) {
s = "newString";
System.out.println(s); // newString
}

I thought the first print statement would print "newString" as String is an object, and when we pass objects between methods, changing state of the object in any method reflects across the methods.

View Replies View Related

How To Use NextLine For Strings

May 12, 2015

I am asking the user a question and already have a correct answer. The answer is a string but is more than one word.

When the user types in the correct answer, it still comes up as wrong but I only have the input.next method.

Quote
Why are rabbits ears long?
United states of america
Incorrect!

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved