I am having problems when I try to store 6000000000 in an int variable.
This is the part of script I am having problems with:
Scanner x = new Scanner(System.in);
System.out.println("Please enter a number here:");
int k = x.nextInt();
System.out.println(k);
When I input 6000000000 the output should be the same, but the output is this error:
Exception in thread "main" java.util.InputMismatchException: For input string: "6000000000"
at java.util.Scanner.nextInt(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
What is this? How to prevent this?
The value is too big, java
ints can only hold values from –2,147,483,648 to 2,147,483,647.Use a
longinstead.