Write a Java-program to check the given character is capital letter or not

Write a Java-program to check the given character is capital letter or not

Program
public class Main
{
    public static void main(String args[])
    {
        char ch='R';
        if(ch>='A' && ch<='Z')
        {
            System.out.println("Capital Letter");
        }
        else
        {
            System.out.println("Not a Capital Letter");
        }
    }
}	

Output:

Capital Letter

Using CommandLine Arguments
public class Main
{
    public static void main(String args[])
    {
        char ch;
        ch=args[0].charAt(0);
        if(ch>='A' && ch<='Z')
        {
            System.out.println("Capital Letter");
        }
        else
        {
            System.out.println("Not a Capital Letter");
        }
    }
}	

Output:

Capital Letter

Using Scanner Class
import java.util.*;
public class Main
{
    public static void main(String args[])
    {
        char ch;
        Scanner s=new Scanner(System.in);
        System.out.println("Enter character");
        ch=s.next().charAt(0);
        if(ch>='A' && ch<='Z')
        {
            System.out.println("Capital Letter");
        }
        else
        {
            System.out.println("Not a Capital Letter");
        }
    }
}	

Output:

Enter character
R
Capital Letter





More Questions


31 . Write a Java-program to check the given character is small letter or not
32 . Write a Java-program to check the given character is capital letter or not
33 . Write a Java-program to check the given character is number or not
34 . Write a Java-program to check the given character is symbol letter or not
35 . Write a Java-program to calculate simple interest with following condtions
36 . Write a Java-program to print age
37 . Write a Java-program to print Max Number amoung the three numners using else if
38 . Write a Java-program to check the given character is vowel or consonant( Character must be small letter)
39 . Write a Java-program to check Odd or Even number program using nested if condition(value must be positive)
40 . Write a Java-program to check Odd or Even number using switch
41 . Write a Java-program to check Vowel or Consonant using switch