-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMath3.java
More file actions
31 lines (27 loc) · 1009 Bytes
/
Copy pathMath3.java
File metadata and controls
31 lines (27 loc) · 1009 Bytes
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
public class Math3 {
public static void main(String[] args)
{
String text = "To be or not to be, that is the question;"
+ "Whether `tis nobler in the mind to suffer"
+ " the slings and arrows of outrageous fortune,"
+ " or to take arms against a sea of troubles,"
+ " and by opposing end them?";
int spaces = 0,
vowels = 0,
letters = 0;
for (int i = 0; i < text.length(); i++){
char ch = text.charAt(i);
if(Character.isWhitespace(ch)){
spaces++;
}
else if (Character.isLetter(ch)) {
letters++;
if ("aeiouAEIOU".indexOf(ch) != -1) {
vowels++;}
}
}
System.out.println("The text contained vowels: " + vowels + "\n"
+ "consonants: " + (letters - vowels) + "\n"
+ "spaces: " + spaces);
}
}