• Register
1 vote
81 views

Problem:

I am looking for a solution to my existing code. Well, I am a new student of java. I was thinking about a program that can check whether the given char is an upper case or not!

Let’s say I’ve given a char as ‘a’ and I want to check this char is in upper case or lowercase! So, my question is, how to check whether a char variable ch is an uppercase letter, you write?

Thanks for your valuable time and effort guys.

12 7 7
15,250 points

1 Answer

1 vote
 
Best answer

Solution:

You got a nice question, man. It is easily can be founded in java whether the input is an uppercase or lowercase by calling a function name toUpperCase(). It returns a boolean type value, but I decided t write a code for you where we can check our input in various ways. Let’s do it.

 

public class UperCaseLowerCase 
{ 
    static void checker(char ch)  
    {  
        if (ch >= 'A' && ch <= 'Z')  
            System.out.println("\n" + ch +  
                    " is an UpperCase character");  
      
        else if (ch >= 'a' && ch <= 'z')  
            System.out.println("\n" + ch +  
                    " is a LowerCase character" );  
      
        else
            System.out.println("\n" + ch +  
                    " is not an aplphabetic character" );  
    }  
  
    public static void main(String []args) 
    {  
        char ch;  
        ch = 'A';  
        ch = 'a';
        ch = '0';  
        checker(ch);  
        checker(ch);  
        checker(ch);  
      
    }  
} 

This program should throw back the output below:

A is an UpperCase character
a is a LowerCase character
0 is not an alphabetic character

Please reply to this thread if you have confusion regarding to this answer. Keep asking, please.
Thanks.

13 9 6
94,240 points

Related questions

0 votes
1 answer 28 views
28 views
I am very new at java programing, I have an assginment where I have to check if a character is uppercase in java and I wrote a code: public static void main(String[] args) { int A; char a = A; if (Character.isUpperCase()) { System.out.println(a + " is an uppercase character."); } } But it doesn&rsquo;t work how. Can anyone help me out?
asked Mar 15 LizzyM 6.1k points