vendredi 4 mai 2018

program to show if the value is alphabet then print "Alphabet" if it’s a number then print "Digit" and for other characters print "Special Character"?

I have completed the program but in case of negative numbers it shows special character but I don't want that I want it should display number.

public class DigitAlphabetSpecialCharacter {
public static void main(String args[])
{
    Scanner scanner=new Scanner(System.in);
    char char1 =scanner.next().charAt(0);
    if(char1>=48 && char1<=57)
    {
        System.out.print("char is Digit");

    }
    else if((char1>='a' && char1<='z')||(char1>='A' && char1<='Z'))
    {
        System.out.print("char is Alphabet");
    }
    else
    {
        System.out.print("char is special character");

    }
}

} can anyone tell how to use negative numbers'ASCII value or an alternative suggestion?

Aucun commentaire:

Enregistrer un commentaire