-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharacterTest.java
More file actions
41 lines (28 loc) · 1.02 KB
/
CharacterTest.java
File metadata and controls
41 lines (28 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* This program demonstrate some of the Characters
* class's character testing method.
*/
import java.util.Scanner;
public class CharacterTest
{
public static void main(String[] args)
{
char ch;
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter any single character: ");
ch = keyboard.nextLine().charAt(0);
//Test the character
if (Character.isLetter(ch))
System.out.println("This is a letter.");
if (Character.isDigit(ch))
System.out.println("This is a digit.");
if (Character.isLowerCase(ch))
System.out.println("This is a lowercase letter.");
if(Character.isUpperCase(ch))
System.out.println("This is a uppercase letter.");
if(Character.isSpaceChar(ch))
System.out.println("This is a space.");
if (Character.isWhitespace(ch))
System.out.println("This is a whitespace character.");
}
}