+ 1
Can someone please explain the error in this simple program?
import java.util.Scanner; public class First { public static void main(String[] args) { int num; Scanner in = new Scanner(System.in); System.out.println("Enter the number"); num= in.nextInt(); System.out.print("You entered " +num); } } Output Enter the number Warning\Error Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java) at java.util.Scanner.next(Scanner.java) at java.util.Scanner.nextInt(Scanner.)
4 ответов
+ 10
//i don't think there is any error in the program run it again , might some connection problem
//its working fine ... i checked ☺
+ 10
about your code, i did similars yesterday and i had a dubt. how we can controll that input is of the right tipe and not for example a letter?
+ 10
@david ... for that u can use try and catch block ...
hope it helps ☺
+ 9
sometimes the IDE run the last project and cause problems . Try again. Also for me your code is right.