Click here to Skip to main content
15,888,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Type your age

Exception in thread "main" java.util.NoSuchElementException
at java.base/java.util.Scanner.throwFor(Scanner.java:937)
at java.base/java.util.Scanner.next(Scanner.java:1594)
at java.base/java.util.Scanner.nextInt(Scanner.java:2258)
at java.base/java.util.Scanner.nextInt(Scanner.java:2212)
at myFirstInput.main(myFirstInput.java:7)

What I have tried:

Java
import java.util.Scanner;

public class myFirstInput {
    public static void main(String[] args) {
        Scanner kbd = new Scanner(System.in);
        System.out.println("Type your age");
        int x = kbd.nextInt();
        System.out.println(x);
    }
}
Posted
Updated 15-Jun-22 11:10am
v2

1 solution

If I try your code by copy'n'paste into an online compiler (Online Java Compiler[^]) it does exactly what I expected: asks for an input, and prints the number I typed.

So ... I suspect it's how you are compiling and running your code, rather than a problem with it. Start by looking closely at exactly what your are doing to build your app, and then at how you re running it.

Sorry, but we can't do any of that for you!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900