Well this little thing is killing me. I am quite a rookie in Java and, have been trying every possible possibility out there and nothing seems to work.
I just want the program to either reject non numerical strings, or ignore letters when pressed on keyboard.
import java.util.Scanner;
public class practice7 {
public static void main(String[] args) {
System.out.println(" Wlecome to the Magellan School student assistant \n\n");
System.out.print("Please Enter your Student ID: ");
Scanner sc = new Scanner(System.in);
Scanner NS = new Scanner(System.in);
int ID = sc.nextInt();
//PRETTY SURE IT GOES HERE...
//rest of program
I have tried all the answers given here, but every time I write letters I get this:
Please Enter your Student ID: ee
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:909)
at java.util.Scanner.next(Scanner.java:1530)
at java.util.Scanner.nextInt(Scanner.java:2160)
at java.util.Scanner.nextInt(Scanner.java:2119)
at practice7.main(practice7.java:11)
Java Result: 1
BUILD SUCCESSFUL (total time: 4 seconds)***