Java Basic stringing help
Hello everyone. I just started a java class and now we are starting strings. I have my program where you are supposed to enter a string of characters and it counts how many there are. However, in the output it seems to skip over words with spaces. The program will work for single words like "the" but when it becomes "The lord of the rings" it still only counts the first word. Here is what it looks like
Code:
# System.out.println("**Test String Operations**");
# System.out.println("");
# System.out.println("Enter a string of Characters:");
# String stringOne=keyboard.next(); // Here i think is the first problem. keyboard.next seems to only get the first string and not the spaces and words after that.
# int stringLength = stringOne.length();
# System.out.println("The length of the string"+" "+stringOne +" "+ "is" +" " +stringLength);
# System.out.println("Enter an integer between 0 and"+" " + stringLength+":"); //also get an error here when the stringOne Input is with spaces
# int index = keyboard.nextInt();
# System.out.println("The character at Index"+" "+index +" "+ "of the string"+" " + stringOne+ " " + "is"+ " " +stringOne.charAt(index));
# System.out.println("Enter another string of Characters:");
# String stringTwo = keyboard.next();
# System.out.println("The first Occurance of the String"+" "+stringTwo+" "+ "in the string"+" "+ stringOne+ " "+"is at position"+" "+stringOne.indexOf(stringTwo));
Here is what the output needs to look like
Enter a string of characters: The Lord of the Rings
The length of string "The Lord of the Rings" is 21
Enter an integer between 0 and 20: 10
The character at index 10 of string "The Lord of the Rings" is 'f'
Enter another string of characters: Lord
The first occurrence of string "Lord" in string "The Lord of the Rings" is at position 4
any help would be appreciated thanks