I want to validate the user input before the program continued. For example:
A variable String name. The program displays 'Enter name' and if the user types in a number instead of a String, a message should pop up and also make the user assign a String to name.
This is what I have so far:
System.out.println("Enter name");
String name = input.nextLine();
I tried try/catch but that did not work. I tried using
if(input.hasNextInt()){System.out.println("Type in a string!");}
but that carries on through the program and still assigns a number to 'name'. It does not give the user a second chance to assign a string to 'name'