Hi all,
I just have a code like this, and well I was trying some things and saw that InputMismatchException and NoSuchElementException work in the same way ... so what is the difference? the api says that NoSuchElementException is used when the "input is exhausted" but I do not understand what it means.
Here are the codes I was using.
import java.util.InputMismatchException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
try{
int a = in.nextInt();
System.out.println("The value of a is:" + a);
}
catch(InputMismatchException e){
System.err.println("Only numbers");
in.nextLine();
}
}
}
import java.util.NoSuchElementException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
try{
int a = in.nextInt();
System.out.println("The value of a is:" + a);
}
catch(NoSuchElementException e){
System.err.println("Only numbers");
in.nextLine();
}
}
}
Thanks,