top of page
Writer's pictureRahul Kumar

Find Character Case

Write a program that takes a character as input and prints either 1, 0 or -1 according to the following rules.


1, if the character is an uppercase alphabet (A - Z)

0, if the character is a lowercase alphabet (a - z)

-1, if the character is not an alphabet


Input format :
Single Character

Output format :
1 or 0 or -1
Constraints :
Input can be any character
Sample Input :
v
Sample Output :
o

Solution:


import java.util.Scanner;
public class Solution {
    
    public static void main(String[] args) {
        // Write your code here
      Scanner input = new Scanner(System.in);
      
       char ch = input.next().charAt(0);
        
        if (ch >= 'A' && ch <= 'Z'){
            System.out.println(1);
            return;
        }
        if (ch >= 'a' && ch <= 'z'){
            System.out.println(0);
return;
        }
        System.out.println(-1);
    }
}


Recent Posts

See All

Number Pattern 1

Print the following pattern Pattern for N = 4 1 23 345 4567 Input Format : N (Total no. of rows) Output Format : Pattern in N lines...

Comments


bottom of page