• Register
1 vote
351 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

Please log in or register to answer this question.

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 3 views
3 views
Problem I want a regular expression to check that And here is my validation expression which is for eight characters including one uppercase letter, one lowercase letter, and one number or special character. How I can write a password that must be eight characters including one uppercase letter, one special character, and alphanumeric characters?
asked Mar 10 neeraj 9.5k points
0 votes
1 answer 15 views
0 votes
1 answer 2 views
2 views
Problem: I am stuck with this line for a long time.Someone please help me.how to delete a char from a string java
asked 1 day ago ashik 10.7k points
0 votes
1 answer 3 views
3 views
Problem: java how to convert string to char.
asked Mar 26 Dan phillip 4.7k points
0 votes
1 answer 2 views
2 views
Problem: I need help for solving problem in java:delete a char from a string java
asked 1 day ago ashik 10.7k points
0 votes
1 answer 4 views
4 views
Problem: I need someone&rsquo;s help to fix it... java for each char in string
asked Mar 25 Ifra 24.4k points
0 votes
1 answer 62 views
62 views
Problem: I want to know whether the character at a certain index in a string is a number or not in C++. Moreover, I wanna see whether the user entered a number as input to a character variable or some other character. How can I do that?
asked Oct 21, 2020 Code Learner 9.2k points