-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStringChecker.java
More file actions
33 lines (30 loc) · 968 Bytes
/
Copy pathStringChecker.java
File metadata and controls
33 lines (30 loc) · 968 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
32
33
import java.util.Scanner;
class Checker{
int vowelCount, consonentCount;
String vowel;
Checker(){
this.vowelCount = 0;
this.consonentCount = 0;
this.vowel = "aeiou";
}
double[] check(String word){
for (int i=0; i < word.length(); i++){
char singleWord = word.charAt(i);
if (this.vowel.indexOf(singleWord) == -1) ++this.consonentCount;
else ++this.vowelCount;
}
double res[] = {this.vowelCount, this.consonentCount};
return res;
}
}
public class StringChecker{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter Your Word: ");
String word = sc.nextLine().toLowerCase();
Checker checker = new Checker();
double[] res = checker.check(word);
System.out.println("Vowel persent: "+res[0]+". Consonent present: "+res[1]);
sc.close();
}
}