Jump to content

Java While Loop (Help!)

Go to solution Solved by elpiop,

wrong syntax, should be name.length() 

My assignment is to ask the user to enter a name that has to be 5 characters or more. If it is less than 5 I have to repeatedly ask them again and again.

 

So far I have all of the usual input java.util.*;

Declaring a new scanner "Scanner kb = new Scanner (System.in);"

And initially asking for the name "System.out.print("Please enter your name (minimum 5 characters): " );

String name = kb.nextLine();.
 
Now here is the part that I am stuck at, the while loop. So far I have 
"while (name.length < 5)" and I am getting an error "cannot find symbol between the name and length."
 
I also tried converting the string into an int with "Integer.parseInt", that compiled fine but if I type in anything besides a whole bunch of numbers I get an exception.
 
Please help, thank you.
Link to comment
https://linustechtips.com/topic/535489-java-while-loop-help/
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×