#Repeat the Enter Student Name Input Using loop

3 messages · Page 1 of 1 (latest)

polar spear
#

Scanner in = new Scanner (System.in);

System.out.print("Enter student's name: ");
String name = in.nextLine();
while(!name.matches("[a-zA-Z]+")){
System.out.println("Please enter a valid name!");
name = in.nextLine();
}

}

}

I should repeat this: "Enter Student Name."
If the user put a number in the string, if you try it, only "Please enter a valid name!" is repeating.

pallid cloakBOT
#

Hey, @polar spear!
Please remember to /close this post once your question has been answered!