Home »
Java Programs »
Java Basic Programs
Java program to check a given character is a lowercase character or not without using the built-in library method
Given a character, check whether it is a lowercase character or not without using the built-in library method.
Submitted by Nidhi, on February 25, 2022
Problem statement
In this program, we will read a character from the user and check the input character is a lowercase character or not without using any built-in library method.
Java program to check a given character is a lowercase character or not
The source code to check a given character is a lowercase character or not without using the built-in library method is given below. The given program is compiled and executed successfully.
// Java program to check a given character is a lowercase character
// or not without using the built-in library method
import java.util.Scanner;
public class Main {
static boolean isLowercase(char ch) {
if (ch >= 'a' && ch <= 'z')
return true;
return false;
}
public static void main(String[] args) {
Scanner X = new Scanner(System.in);
char ch = 0;
System.out.printf("Enter character: ");
ch = X.next().charAt(0);
if (isLowercase(ch))
System.out.printf("Given character is a lowercase character\n");
else
System.out.printf("Given character is not a lowercase character\n");
}
}
Output
RUN 1:
Enter character: x
Given character is a lowercase character
RUN 2:
Enter character: Y
Given character is not a lowercase character
Explanation
In the above program, we imported "java.util.Scanner" package to read input from the user. And, created a public class Main. It contains two static methods main() and isLowercase().
The isLowercase() method returns a Boolean value based on input character, it returns true if a given character is a lowercase character otherwise it returns false.
The main() method is an entry point for the program. Here, we read a character from the user and checked input character is a lowercase character or not and printed the appropriate message.
Java Basic Programs »