-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindTypes_Assignment3.java
More file actions
37 lines (28 loc) · 1.05 KB
/
FindTypes_Assignment3.java
File metadata and controls
37 lines (28 loc) · 1.05 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
package week1.day2;
public class FindTypes_Assignment3 {
public static void main(String[] args) {
String test = "$$ Welcome to 2nd Class of Automation";
int letter = 0, space = 0, num = 0, specialChar = 0;
int strlength = test.length();
System.out.println("Length of string is " + strlength);
System.out.println("The char is " + test.charAt(5));
char[] charArray = test.toCharArray();
for (int i = 0; i < charArray.length; i++) {
char ch = test.charAt(i);
if (Character.isLetter(ch)) { // Character.isLetter
letter++;
} else if (Character.isDigit(ch)) { // Character.isDigit
num++;
} else if (Character.isSpaceChar(ch)) { // Character.isSpaceChar
space++;
} else { // else -> consider as special character
specialChar++;
}
System.out.println("The CharArray: " + charArray[i]);
}
System.out.println("letter: " + letter);
System.out.println("space: " + space);
System.out.println("number: " + num);
System.out.println("specialCharcter: " + specialChar);
}
}