-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLecture13CheckLetter.java
More file actions
47 lines (45 loc) · 1.28 KB
/
Lecture13CheckLetter.java
File metadata and controls
47 lines (45 loc) · 1.28 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
39
40
41
42
43
44
45
46
47
import java.util.Scanner;
/**
*
* Lecture 13
* implement isLetter method
*
* @author P.M.Campbell
* @version 2020-fall
*
*/
public class Lecture13CheckLetter {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
char letterMaybe;
System.out.print("enter a single char I will tell you if it is a letter a-z or A-Z:");
letterMaybe = in.next().charAt(0);
if (isLetter1(letterMaybe)) {
System.out.println("The input "+ letterMaybe + " is a letter.");
} else {
System.out.println("The input "+ letterMaybe + " is NOT a letter.");
}
if (isLetter2(letterMaybe)) {
System.out.println("The input "+ letterMaybe + " is a letter.");
} else {
System.out.println("The input "+ letterMaybe + " is NOT a letter.");
}
}
public static boolean isLetter1(char testChar) {
// check for lower case letter
if (testChar >= 97 && testChar <= 122) {
return true;
} else if (testChar >= 65 && testChar <= 90) { // check for upper case letter
return true;
}
return false;
}
public static boolean isLetter2(char testChar) {
if (testChar >= 'a' && testChar <= 'z') {
return true;
} else if (testChar >= 'A' && testChar <= 'Z') {
return true;
}
return false;
}
}