
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check If Value Is ASCII 7-Bit Alphabetic Uppercase in Java
In this article, we will explore how to verify whether or not a given character is an uppercase letter and, more specifically, falls within the range of A to Z. This is useful when a user's input consists of some uppercase letter or when a program needs to restrict itself to uppercase letters. We use concepts such as if-else statements, character comparison, and conditional logic to solve this problem.
Problem Statement
We need to write a program that checks if a character falls within the uppercase alphabetic range, which spans from 'A' to 'Z'.Input
The input will consist of a single character.Output
Character: (given char) TGiven character is in uppercase!
Steps to check if a character is uppercase
The following are the steps to check if a character is uppercase -
- Initialize a character variable.
- Use an if-else condition to determine if the character is between 'A' and 'Z'.
- Print a message based on the result.
Java program to check if a character is uppercase
The following is the Java program to check if a character is uppercase ?
public class Demo { public static void main(String []args) { char one = 'T'; System.out.println("Character: "+one); if (one >= 'A' && one <= 'Z') { System.out.println("Given character is in uppercase!"); } else { System.out.println("Given character is not in uppercase!"); } } }
Output
Character: T Given character is in uppercase!
Java program to check if a character is uppercase
The following is the Java program to check if a character is uppercase ?
public class Demo { public static void main(String []args) { char one = 'e'; System.out.println("Character: "+one); if (one >= 'A' && one <= 'Z') { System.out.println("Given character is in uppercase!"); } else { System.out.println("Given character is not in uppercase!"); } } }
Output
Character: e Given character is not in uppercase!
Code Explanation
In this program, a character variable one is declared and a single letter such as ?T' or ?e' is assigned. Then, the next section of the code uses an if statement to determine whether or not the character is between the range of A - Z capital letters. If it is, then the program states that the character is in uppercase, otherwise it states that it is not the case. These simple methods are used to check whether the given is uppercase characters.