Hello everyone. I'm new to Java and I'm trying to check if the user is inputting a word, or a number. We were just introduced to while loops in class and I figured I'd try one out. My program worked up until I tried to validate what the user is inputting.
My problem is that the input doesn't stop and the user can just keep hitting return.
*** Disclaimer, I'm just messing around and the text doesn't mean anything.
import java.util.Scanner; public class SchoolDegree { public static void main(String[] args) { System.out.print("Please enter your school name: "); Scanner in = new Scanner(System.in); String schoolName = in.nextLine(); while (in.hasNextLine()) { if (schoolName.equals("Syracuse")) { schoolName += ", aka CUUUUUSE."; } else if (schoolName.equals("Ohio")) { schoolName += ", aka NO SOUP FOR YOU."; } else schoolName += ", aka who?"; } while (in.hasNextInt()) { System.out.println("How can your school be a number?"); } System.out.println("You attend " + schoolName); } }