Java while loop

9 Views
Published
Java while loop

#Java #while #loop

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

// while loop = executes a block of code as long as a it's condition remains true

Scanner scanner = new Scanner(System.in);
String name = "";

while(name.isBlank()) {
System.out.print("Enter your name: ");
name = scanner.nextLine();
}

System.out.println("Hello "+name);

}
}
Category
Bro Code
Tags
java while loop, java while loop user input, java while loop tutorial
Be the first to comment