- I have a main function in which I use Scanner to read an integer from the console.
- Inside this main function, we can access another function which also uses the Scanner to read an integer.
- The program "swings" between these two functions many times.
The problem is that the Java.util.Scanner throws an exception.
Is there any way to overcome this?
import java.util.Scanner;
public class dummy {
public static void main(String[] args) {
int buy;
Scanner sc = new Scanner(System.in);
buy = sc.nextInt();
user = dummy2();
sc.close();
}
private static boolean dummy2() {
Scanner sc1 = new Scanner(System.in);
// Code...
sc1.close();
}
}