I am trying for a logic that i have some emp ids as a string seperated by commas and i need the substring of emp ids as below. splitting the string as below.
public static void main(String args[]) {
String empId = "1,2,3,4,5,6,7,8,9,10";
int i;
int count = 9;
for (i = 0; i <= count; i = i + 3) {
System.out.println("Emp IDs are : " +empId);
}}
Result is:
Emp IDs are : 1,2,3,4,5,6,7,8,9,10
Emp IDs are : 1,2,3,4,5,6,7,8,9,10
Emp IDs are : 1,2,3,4,5,6,7,8,9,10
Emp IDs are : 1,2,3,4,5,6,7,8,9,10
But I want the result like:
Emp IDs are : 1,2,3
Emp IDs are : 4,5,6
Emp IDs are : 7,8,9
Emp IDs are : 10
(Check substrings) You can check whether a string is a substring of another string by using the indexOf method in the String class. Write your own method for this function. Write a program that prompts the user to enter two strings, and checks whether the first string is a substring of the second.
What the function should return
public class Ex2 { public static void main(String[] args) { System.out.println("Input the first string:"); Scanner input = new Scanner(System.in); String firstString = input.nextLine(); System.out.println("Input the second string:"); String secondString = input.nextLine(); check(firstString,secondString);
The number of dot separated segment in front of the string may vary, but it doesn't matter since I only need to extract the last two segments from the string (int this case : 33423 and AMDAC-4). How do I do this efficiently? I need to process hundreds of thousands of these strings every day. it is guaranteed that the segments will always be separated by dots only (no whitespaces in the string)
I was working on my personal project when I realized I needed to split a string and extract 2 elements of it. The way it works is the user enters 2 numbers separated by a comma like this: 4, 8. Then I want to put the first number into a veriable called x and the next number into a variable called y. How can I do this?
double sum = a + b + c; System.out.printf("Sum = %d", sum);
Heres the error I'm getting
Enter three positive integers separated by spaces, then press enter: 15 20 9
Sum = Exception in thread "main" java.util.IllegalFormatConversionException: d != java.lang.Double at java.util.Formatter$FormatSpecifier.failConversion(Unknown Source) at java.util.Formatter$FormatSpecifier.printInteger(Unknown Source) at java.util.Formatter$FormatSpecifier.print(Unknown Source) at java.util.Formatter.format(Unknown Source) at java.io.PrintStream.format(Unknown Source) at java.io.PrintStream.printf(Unknown Source) at project2.main(project2.java:52)
I would like to get commas in my output for bigger numbers like 1,000.00 10,000.00 etc...This is my program. Everything compiles just fine and I get the right output but again would like commas.
import java.text.DecimalFormat; import java.util.Scanner; import java.io.*; public class propertyTax { public static void main(String[] args) throws IOException { String fileName; double assessedValue;
[Code] ....
These are some of the values that are in/outputted :
I've almost got this to work. Right now it prints out one comma for the first set of 3 numbers. For exmaple, if the user input is 12345678 the code will print out 12345,678. I'm trying to figure out how to get it to print out commas for the rest of the numbers. My first thought was to use a loop but I can't get it to work....
private static void printWithCommas(NaturalNumber n, SimpleWriter out) { assert n != null : "Violation of: n1 is not null"; assert out != null : "Violation of: out is not null"; assert out.isOpen() : "Violation of: out.is_open"; if (n.compareTo(THOUSAND) < 0) { out.print(n);
public class ArrayPrinter { public static void main(String[] args) { int[] oneD = {5, 6, 7, 8}; PrintArray(oneD); } public static void PrintArray(int[] Arr) { System.out.println ('['); for (int i =0; i >= Arr.length; i++) { System.out.print (Arr[i]); if (i < Arr.length){ System.out.print(", "); } System.out.print (']'); } } }
I tried to format this to enhance readability but I'm not sure if I managed to improve it any... This code should be printing the contents of the array with spaces and commas its just printing [. I think this is because Arr is empty for some reason but I'm not sure why it would be when it gets the values of oneD passed to it.
Write a program that reads number between 1,000 and 999,999 from the user and prints it without a comma separating the thousands. Read the input as string. Find the length of the string and use the substring to break it into two pieces. Do not include the comma. You can then concatenate using the + symbol to reassemble without the comma. For example if the number is 123,456. First would equal 123 and second would equal 456. noCommaNumber - 123456.
I do not think it is required to only allow numbers in that range in the code. My question is how to get the first half of the number before the comma in a string to make the last line work. What I think is not doing what I need is the line String first = numberIn.substring(numberIn.indexOf(",", 0)); This is just the last thing I tried.Getting the second half is done using IndexLastOf method in the substring class javaforumquest.jpg
I have to alter my Sentence class to find the index of the substring "sip" in Mississippi but I'm really not sure where to begin. This is what I have...
Sentence.java public class Sentence { private boolean outcome; private String sentence; public Sentence(String aSentence) { sentence = aSentence;
[Code] ....
I know that I need to change public boolean find(String t) to public int indexOf(String t) but I'm not sure what to start doing to get the index of "sip".
I'm still working with the singlylinkedlist data structure and trying to return a string of individual characters stored in each node. ( head--('J')---('A')---('V')---('A')---tail ) Hopefully this beautifully executed depiction to the left will clarify.
This is what I came up with after designing the algorithm w/ pen and paper. I know that I'm not accounting for the OutOfBound errors, an empty list, or an index < 0.... I will get to that.
Right now, I'm not sure why my assignment to the character array, ' chars[i] = cursor.getLink(getElement()); ' , is not working. The two methods getLink and getElement, type Node and T, respectively, exist in my Node class which is a private nested class in MySLList. Why would I be getting the following error: "The method getElement() is undefined for the type StringX" ? Is this a good design and implementation of the substring method?
public String substring(int index) { char[] chars = new char[(getSize() - index)]; //getSize() defines the size of list in MySLList Node cursor = null; //Set the cursor to the node = index if(cursor == head) {
I am working on my homework, and everything is fine. But I was wondering if I can fix one thing. basically it prompt from a user for a text file name and save the content as an array. some part of my code is here:
public class arraysort{ static BufferedReader kb = new BufferedReader(new InputStreamReader(System.in)); public static void main(String[] args) throws Exception { System.out.print("Enter the first name of the file: "); String input = kb.readLine(); int[] firstArray = readFile(input); firstArray = bubbleSort(firstArray);
Basically it prompt from a user for a text file name and save the content as an array. some part of my code is here:
public class arraysort{ static BufferedReader kb = new BufferedReader(new InputStreamReader(System.in)); public static void main(String[] args) throws Exception { System.out.print("Enter the first name of the file: "); String input = kb.readLine();
[Code] ....
As you you may figure, it works if I put numbers separated by each lines. I was wondering if I can change it so that it works when I put numbers separated by space rather then each lines.
I am cleaning up print logs from an old system to be used in excel. I can get them down to each value is separated by a comma and looks like this.
TIME,1009 9/18/14,F/A RATIO,0.7590,NET AIR CNTS,66018.2,NET FLAG CNTS,50107.5,BKGROUND CNTS,61.0BW OF FLAG,49.807,DFRAC,-0.1834,ZFRAC,0.0000UP AIR TEMP,104.32,LO AIR TEMP,98.51,SOURCE TEMP,91.11,RCVR TEMP,97.95,,UP HEAD TEMP,93.89,LO HEAD TEMP,81.26
TIME,1026 9/18/14,F/A RATIO,0.7589,NET AIR CNTS,66026.3,NET FLAG CNTS,50107.4,BKGROUND CNTS,61.0BW OF FLAG,49.829,DFRAC,-0.1660,ZFRAC,0.0000UP AIR TEMP,104.93,LO AIR TEMP,98.42,SOURCE TEMP,92.65,RCVR TEMP,99.49,,UP HEAD TEMP,94.82,LO HEAD TEMP,82.23
TIME,1042 9/18/14,F/A RATIO,0.7584,NET AIR CNTS,66076.3,NET FLAG CNTS,50109.2,BKGROUND CNTS,61.0BW OF FLAG,49.955,DFRAC,-0.0652,ZFRAC,0.0000UP AIR TEMP,104.72,LO AIR TEMP,97.91,SOURCE TEMP,93.36,RCVR TEMP,99.52,,UP HEAD TEMP,95.31,LO HEAD TEMP,82.47
Where value follows its header. how can i export this to csv or excel with rows and columns?
I am trying to write a program that will take any comma separated data set and return the values in an arraylist without any commas. Like if I input "hello, world, program, java" it would output an arraylist [hello,world,program,java].
public void run(){ String line = readLine("Enter a CSV-formatted line of data: "); int lowerBound = 0; String entry = new String(""); ArrayList<String> string = new ArrayList<String>();
I have seen in some examples like URL... a good design is to have the model and the action methods in one just single bean and the model not to be a separated class but a few properties like this:
public class CustomerBean implements Serializable{ //DI via Spring CustomerBo customerBo; [b]public String name;[/b] [b]public String address;[/b] //getter and setter methods
[code]...
Some questions:
1. If you are using hibernate or any other ORM like the above example(URL...), why not to use the hibernate pojo bean directly like it represented the form instead of using properties?:
public class CustomerBean implements Serializable{ //DI via Spring CustomerBo customerBo; [b]Customer customer;[/b] //represents the properties of a form //getter and setter methods public void setCustomerBo(CustomerBo customerBo) { this.custom
2. Why is it said that JSF represents the purest MVC? Spring separates the model from the view too and Struts does too. I dont really understand it
The first line is the number of test cases and the second line is the corresponding values for the test cases. Java code for taking multiple inputs in the single line separated by a space.
public class Fibonacci { public static int fib(int n) { if (n < 2) {return n;} else {return fib(n-1)+fib(n-2);}
[code]....
it contains one method called fib() and one main method.If I would want to have the main method in another class than fib(), how would I write the two classes? Only cutting the main method from this class to another one doesn't work.My question is, is the reason it doesn't work because I then would have to have a constructor in the Fibonacci class, and create a Fibonacci object first which I then use the method on?
How can I write a method that takes a string with duplicates letters and returns the same string which does not contain duplicates. For example, if you pass it radar, it will return rad. Also i would like to know how can I Write a method that takes as parameters the secret word and the good guesses and returns a string that is the secretword but has dashes in the places where the player has not yet guessed that letter. For example, if the secret word is radar and the player has already guessed the good guesses letters r and d, the method will return r-d-r.