Here is my error code:
Please enter an animal: Now enter another: Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Scanner.java:…
at strings.main(strings.java:18
And here is my code:
import java.util.Scanner ;
public class Strings {
public static void main (String[] args) {
Scanner input1 = new Scanner(System.in);
Scanner input2 = new Scanner(System.in);
Scanner input3 = new Scanner(System.in);
//Get input from user
System.out.print("Please enter an animal: ");
String animal1 = input1.nextLine();
System.out.print("Now enter another: ");
String animal2 = input2.nextLine();
System.out.print("One more, please: ");
String animal3 = input3.nextLine();
//First manipulation - Print the strings back out
System.out.println("You entered " + animal1 + ", " + animal2 + ", and " + animal3 + ".") ;
//Second manipulation - Print the length of the second string
System.out.println("Your second animal is " + (animal2.length()) + " letters long.") ;
//Third - Print the first string concatenated with the second
System.out.println ("Your first and second animals were " + animal1 + ", and " + animal2);
//Fourth - Print "true" if the first and second strings are the same, false if otherwise
System.out.print("The first and second animal are the same: ");
if (animal1==animal2) {
System.out.println("true.");
}
else {
System.out.println("false.");
}
//5 - Print out where the first character "c" appears in the first string, -1 if it doesnt
System.out.println("Where is the letter C in the first animal? Look at letter number " + animal1.indexOf('c')) ;
//6 - Print out where the third string appears in the second one, or -1
System.out.println("Where does the third animal appear in the second one?: " + animal2.indexOf(animal3)) ;
//7 - Print the second string in all capital letters
System.out.println("YOUR SECOND ANIMAL IN ALL CAPITAL LETTERS IS: " + animal2.toUpperCase() + "!") ;
//8 - Interpret the third string as an interger, add it to 10, print the result.
Integer i = Integer.decode("123");
System.out.println("If your third animal was a number, and I added ten to that number, it would be:" + i+10)
} //end main
} //end class
I'm sure there's a lot of other errors as well, so please point them out! Thank you!