I am currently trying to split the string "EAM est" between the part. I have gotten the code to work if the was a -. But I can't see why the error is occuring
I am writing a program where I need to split an array of full names into First names and Surnames, using mapping. However, I am struggling how to split it up... and my First Names and Surnames list are both just displaying the full name.
public static void main(String[] args) { String[] names; names = new String[8]; Scanner s = new Scanner(System.in); for (int i = 0; i < names.length; i++) { System.out.println("Enter full student name:");
I am trying to split a string into a String[] tokens array to declare variables for an object; however, I'm having an issue getting the string to tokenize correctly. Here's an example of the input:
a : 100 : John Smith : 20 Main St. a : 101 : Mary Jones : 32 Brook Rd.
Here is the basic code I have now, to properly sort each line of text, etc. (without the split() method):
Java Code:
while (scanner.hasNextLine()) { currentLine = scanner.nextLine(); lineScan = new Scanner(currentLine); if (currentLine.startsWith("/") || currentLine.trim().isEmpty()) continue;
[Code] ....
I was able to eliminate the comments and identifiers from the text by trimming the first two characters of the string. For the split, I tried String[] tempArray = currentLine.split("s+"); however, that also took the spaces out of the addresses and names...so the results looked like this:
100 John Smith 20 Main St.
As you can see, it splits via space regardless, including where I replaced all the :'s with spaces. Is there any way to do this?
I have an requirement of splitting a Date-Time String i.e. 2013/07/26 07:05:36 As you observe the above string has Date and Time with space in between them.
Now I want just want split the string not by delimiter but by length i.e. after 10th place and then assign it to 2 variable i.e. Date <----2013/07/26 and Time <---07:05:36 separately.
I am developing a project where i have to split a zip file into fragments. Do we have any code for this splitting of zip files. I upload a zip file and it has to split into fragments and these fragments has to be renamed. I am having problem with splitting the zip file.
I've written a program just for the sake of it (to learn) and it seem's like theres quite a lot in the main method that perhaps could be split up into seperate classes. I'm not too sure where should start with this though, or what my thought process should have been as I was writing the program.
import java.util.Scanner; public class Loops { public static void main(String[] args) { int answer = 16; Scanner scan = new Scanner(System.in); // Question System.out.println("What is 4 x 4 ?");
[code]...
--- Update ---
here's a version without code comments as they might make it harder to read here -
import java.util.Scanner; public class Loops { public static void main(String[] args) { int answer = 16; Scanner scan = new Scanner(System.in); System.out.println("What is 4 x 4 ?"); int userAnswerInt = 0;
I'm trying to create a Java swing chess application, but would like to divide the GUI part of it into at least two different classes (possibly more later, but I'm not sure yet). Currently I have a mainGUI class and a ChessBoard class, both of which extend JFrame. I want the main GUI class to contain a JPanel which will house several components, including a JPanel originating from the chessboard class that contains the actual board.
Is there any way to do this? I tried just creating a ChessBoard object in my main GUI class and then adding it to the component, but I got an illegal argument exception, because apparently you can't add one JFrame to another. How to do what I'm trying to do, or just how to split GUIs into multiple classes in general?
Me and my mate are struggling to get our code to split a line in a text file which are separated by (":") and store into an array. We've managed to split each individual line into an array, but cannot work out how to do it with multiple splits over one line.
public class op{ String word = "Hello"; //my variable public void reverseword() //My function { for(int i =word.length();i>=0 ;i--) { System.out.println(word.charAt(i));
[code]....
when i call function in main i have this error:
run: Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 5 at java.lang.String.charAt(String.java:658) at javacourse.Car.opname(Car.java:35) at javacourse.JavaCourse.main(JavaCourse.java:24) Java Result: 1
I'm writing basically my first program for school. I've written small ones, following instructions, but this is the most vague. I'm having issues. I can't figure out what the error means. I'm not done with the code, but I think the ArrayList is throwing me off. I'm trying to gather user input and sum the total. Here's the code:
package graduationplanner; import java.util.ArrayList; import java.util.Scanner; import java.lang.Double; public class GraduationPlanner { public static void main(String[] args) {
I have this error that keeps coming up any time I select one of my buttons. It actually doesn't hinder the performance of the project, everything works. But I am concerned I missed something and errors are never a good sign.On a slightly different note, I would like to figure out what the best way to format my output would be? I would like it to display as "100.00 F". I have a couple ideas on how to get the F symbol (or other symbol) by inserting something like
String degreesymbol = "F" or whichever it is and then returning that in the output string later. I can't get the decimal formatted correctly and I don't know how to print the degree symbol.Here is the code
I'm having a small error with my code, it is getting rid of the first letter of the string after the first line printed.
import java.util.*; public class PrintPyramidName { public static void main(String[] args) { System.out.println("What is your name?"); Scanner input = new Scanner(System.in);
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String ind ex out of range: 10 at java.lang.String.charAt(String.java:658) at StringChar.main(StringChar.java:11)
Code :
class StringChar{ public static void main(String ss[]){ String str="HelloWorld"; int a; System.out.println("String is = " + str); a=str.length(); System.out.println("String is After Reverse"); for(int i=a;i>=0;i--) System.out.print(str.charAt(i)); } }
I have a .txt file which i am currently using Scanner to input into the console, the text file contains the names of football games followed by their scores:
E.g. Man U : Liverpool : 2 : 1
I need to create an equation to add together all scores to create a string reading something like "total goals: 28" ....
I am having issues with the program below everything works but I can't figure out a way to add code that if a user just hits enter without inputting anything it says "entering in nothing is not a valid choice" I am stuck on how to compare a int to a string ...
//import statements import java.util.*; //for scanner class // class beginning public class Guess { public static void main(String[] args ) { //Declare variables area