I want to say I'm new to Java so please don't hate me for my messy code. System.out.print("Enter your name") is not repeated if you will not enter anything on your keyboard. Loop goes around but this statement is not repeated. If you enter some letters the print statement is executed and I don't know why. Here is a picture to make it more clear. Probably it is a very easy mistake I made but I can't see it. Thanks for any help or clue how to solve this problem.
That's how it looks like:
That's how I want it to be:
package loop;
import java.util.Scanner;
public class while_loop
{
public static void main(String[] args)
{
String word2 = null;
boolean T_F = true;
while (T_F == true)
{
System.out.print("Enter your name:");
Scanner in = new Scanner(System.in);
word2 = in.next().toUpperCase();
if (word2 != null && word2.length() > 3)
{
in.close();
T_F = false;
System.out.println("Done");
}
}
}
}
Ehh OK solved. Small little mistake.
word2 = in.next().toUpperCase();
should be
word2 = in.nextLine().toUpperCase();