-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsingStrings.java
More file actions
40 lines (35 loc) · 1.09 KB
/
Copy pathUsingStrings.java
File metadata and controls
40 lines (35 loc) · 1.09 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
import acm.program.ConsoleProgram;
public class UsingStrings extends ConsoleProgram {
/*
public boolean isVocal(char c) {
String vocals = "AEIOUaeiou";
char[] vocalsChars = vocals.toCharArray();
int i = 0;
while (i < vocalsChars.length && vocalsChars[i] != c) {
i += 1;
}
return i < vocalsChars.length;
}
public String removeVocals(String str) {
char[] resultChars = new char[str.length()];
int resultLength = 0;
for (int i = 0; i < str.length(); i++) {
char current = str.charAt(i);
if (!isVocal(current)) {
resultChars[resultLength] = current;
resultLength += 1;
}
}
return new String(resultChars, 0, resultLength);
}
public void run() {
String sentence = readLine("Enter a sentence: ");
String result = removeVocals(sentence);
println("The sentence w/o vocals is: " + result);
return null;
}
*/
public static void main(String[] args) {
new UsingStrings().start(args);
}
}