// ClassifyChar2.java
// Classifies the characters in a
// command-line argument of <= 15 characters,
// using logical operators.

public class ClassifyChar2  {
   public static void main(String[] args)
   {
      if ( args.length == 0 || args[0].length() > 15 )
      {
         System.out.println("This program classifies the "
                            + "characters in a single");
         System.out.println("command-line argument no more than "
                            + "15 characters long.");
         System.exit(0);
      }  // if user error

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

      String text = args[0];

      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 == ' ' )   // but this case will never happen
                                // with command-line argument input.
            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 ClassifyChar2