-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSentenceModify.java
More file actions
64 lines (61 loc) · 1.95 KB
/
Copy pathSentenceModify.java
File metadata and controls
64 lines (61 loc) · 1.95 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package basic;
import java.io.*;
import java.util.StringTokenizer;
class SentenceModify {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a sentence");
String str = br.readLine();
str = str.toLowerCase();
int len = str.length();
char c = str.charAt(len - 1);
if (!(c == '.' || c == '?')) {
System.out.println("Entered sentence is not terminated by '.' or '?'");
System.exit(0);
}
str = str.substring(0, len - 1);
str = str.trim();
str = ' ' + str;
len = str.length();
String s = "";
for (int i = 0; i < len - 1; i++) {
if (str.charAt(i) == ' ') {
c = str.charAt(i + 1);
int temp = (int) c - 32;
s += (char) temp;
} else {
s += str.charAt(i + 1);
}
}
System.out.println(s);
s = s.trim();
s = s + ' ';
System.out.println("Word \t\t\t\tVowels \t Consonents");
StringTokenizer st = new StringTokenizer(s);
while (st.hasMoreTokens()) {
display(st.nextToken());
}
}
//Method to display vowels and consonents of word
public static void display(String str1) {
System.out.print(str1 + "\t\t");
str1 = str1.toLowerCase();
int len = str1.length();
int vow = 0, cons = 0;
for (int i = 0; i < len; i++) {
char ch = str1.charAt(i);
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') {
vow++;
} else {
cons++;
}
}
if (len < 7) {
System.out.print("\t \t");
} else {
System.out.print("\t");
}
System.out.print(vow + "\t\t" + cons);
System.out.println("");
}
}