// ClassifyChar3.java
// Classifies the characters in an
// entered string of 1 to 15 characters,
// using logical operators.
// Uses prompted console input.

public class ClassifyChar3  {
   public static void main(String[] args)
   {
      System.out.print("Enter any string of 1 to 15 characters:>");
      String text = ConsoleInput.readLine();
      System.out.println();
      System.out.println("You typed:  " + text);

      while ( text.length() == 0 || text.length() > 15 )  {
         System.out.print("Your string must be 1 to 15 characters:>");
         text = ConsoleInput.readLine();
      }  // while

      System.out.println();
      System.out.println("Position   Character   Classification");
      System.out.println("--------   ---------   --------------");
      System.out.println();

      for ( int i = 0; i < text.length(); i++ )  {

         // Display character's position in String text:
         String positionText = Integer.toString(i);
         for ( int j = positionText.length(); j < 2; j++ )
             positionText = " " + positionText;
         System.out.print("   " + positionText);

         // Display the character itself:
         char x = text.charAt(i);
         System.out.print("          " + x + "       ");

         // Classify the character:
         if ( x > 127 )
            System.out.println("non-ASCII character");
         else if ( x == ' ' )
            System.out.println("ASCII space");
         else if ( x >= '0' && x <= '9' )
            System.out.println("ASCII digit");
         else if ( (x >= 'A' && x <= 'Z')
                  || (x >= 'a' && x <= 'z') )
            System.out.println("ASCII letter");
         else if ( x < 32 || x == 127 )
            System.out.println("ASCII control character");
         else
            System.out.println("ASCII punctuation mark");
      }  // for i
   }  // method main
}  // class ClassifyChar3