Computer Science, asked by 0506nsharma, 4 months ago

write a program in java to check whether the entered data is alphabet or digit. if it is alphabet .then print whether it is capital or small case. If digit is entered, throw user defined exception 'digit not allowed'.​

Answers

Answered by Oreki
1

import java.util.Scanner;

public class InputChecker {

   public static void main(String[ ] args) {

       System.out.print("Enter data - ");

       char data = new Scanner(System.in).next( ).charAt(0);

       if (Character.isLetter(data))

           System.out.println("It is in "

                   + (Character.isLowerCase(data) ? "Lowercase" : "Uppercase"));

       else if (Character.isDigit(data))

           try {

               throw new DigitNotAllowed( );

           } catch (DigitNotAllowed ignored) { }

       else System.out.println("Special Character");

   }

  private static class DigitNotAllowed extends Throwable {

       DigitNotAllowed( ) {

           System.out.println("Digit not allowed!");

       }

   }

}

Similar questions