Sunday, March 11, 2018

Find Character Case

Find character case

Write a program to determine whether the entered character is in uppercase or lowercase, or is an invalid character.

Print
 1 for uppercase
 0 for lowercase 
-1 for any other character (special characters or others)
Input format :
Single Character
Output format :
1 or 0 or -1
Sample Input 1 :
v
Sample Output 1 :
0
Sample Input 2 :
V
Sample Output 2 :
1
Sample Input 3 :
#
Sample Output 3 :

-1



import java.util.Scanner;
public class Main 
{
public static void main(String[] args)
{
  Scanner s = new Scanner (System.in);

char chr = s.next().charAt(0);
if(chr >= 'A' && chr <= 'Z')
{
System.out.println("1");
}
    else if ( chr >='a' && chr <='z') 
{
System.out.println("0");
}
else
{
System.out.println("-1");
}
}


}




No comments:

Post a Comment