I want to make a simple app that reads a string from the keyboard and prints it with a message afterwards. This is my code:
import java.util.Scanner;
public class HelloWorld {
public static void main(String argv[]) {
Scanner keyboard = new Scanner(System.in);
System.out.println("enter an integer");
int myint = keyboard.nextInt();
System.out.println(myint+ " <- that's the string");
}
}
Something is wrong because I get an error message:
Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:862) at java.util.Scanner.next(Scanner.java:1485) at java.util.Scanner.nextInt(Scanner.java:2117) at java.util.Scanner.nextInt(Scanner.java:2076) at HelloWorld.main(HelloWorld.java:25)
How can I solve this?