So I have a question with my code. A part of my code includes a question for a persons details, and to make sure they answer it correctly. The person cannot answer it blank with whitespace or enter etc. If they answer it incorrectly they're supposed to be sent back to the question again and re-enter their details.
This is how far I've come:
System.out.println("Name: ");
String name = scan.nextLine();
if(name.equals(null) || name.equals("")) {
System.out.println("Name can't be empty, please enter again.");
System.out.println("Age: ");
int age = scan.nextInt();
if(age.equals(null) || age.equals("")) {
System.out.println("Age can't be empty, please enter again.");
The thing now is that I'm not quite sure how to handle this if the person answers with whitespace. The code doesn't handle whitespace. Also, how can I make the program automatically go back to ex. "Name:" if it's answered incorrectly?
/Anna