Computer Applications
Write a Java program that takes character as input and checks if it is uppercase or lowercase letter or a digit. Allows the user to enter repeatedly and counts each of the category. Program prints the count when the user stops entering the characters by providing a space as the character input.
Java
Java Library Classes
5 Likes
Answer
import java.io.*;
public class KboatCharCaseCheck
{
public static void main(String args[]) throws IOException {
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);
int uc = 0, lc = 0, dc = 0;
while (true) {
System.out.print("Enter character: ");
char ch = in.readLine().charAt(0);
if (ch == ' ') {
System.out.println("Upper Case Count = " + uc);
System.out.println("Lower Case Count = " + lc);
System.out.println("Digit Count = " + dc);
break;
}
if (Character.isUpperCase(ch)) {
System.out.println("Upper Case letter");
uc++;
}
else if (Character.isLowerCase(ch)) {
System.out.println("Lower Case Letter");
lc++;
}
else if (Character.isDigit(ch)) {
System.out.println("Digit");
dc++;
}
}
}
}
Output

Answered By
1 Like
Related Questions
Chhavi wants to check whether a character variable
ch
contains an uppercase letter (A-Z).She writes the following statement, which is incorrect:
if (ch == "A" && ch == "Z")
What will be the correct statement?
A.
if (Character.isUpperCase(ch))
B.if (ch >= 65 && ch <= 90)
C.if (ch >= 'A' && ch <= 'Z')
Write a Java program to accept a character and print all the characters following it in the reverse order(till a).
Sample input:
If the character entered is d.Sample output:
d
c
b
aAssertion (A): In Java, assigning an
int
value to anInteger
object is valid.Reason (R): Java automatically converts primitive data types to their corresponding wrapper classes, which is called Autoboxing.
String s1 = "45.50"; String s2 = "54.50"; double d1=Double.parseDouble(s1); double d2=Double.parseDouble(s2); int x= (int)(d1+d2);
What is value of x?