Advertisement
Guest User

Untitled

a guest
Sep 24th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.64 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class EnterAgain {
  4.   public static void main(String[] args) {
  5.     Scanner StdIn = new Scanner(System.in);
  6.  
  7.     // Initialize the string to be empty
  8.     // This makes it so that we ALWAYS enter the loop initially no matter what
  9.     String userinput = "";
  10.  
  11.     // Loop indefinitely iff the userinput is empty
  12.     while(userinput.length() == 0){
  13.       System.out.print("Enter a word: ");
  14.       userinput = StdIn.nextLine();
  15.     }
  16.  
  17.     // If we have successfully broken the loop
  18.     // print the userinput length (meaning this can not be an empty string)
  19.     System.out.println(userinput.length());
  20.   }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement