-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathISC2016Q3.java
More file actions
53 lines (51 loc) · 1.76 KB
/
Copy pathISC2016Q3.java
File metadata and controls
53 lines (51 loc) · 1.76 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
import java.util.Scanner;
public class ISC2016Q3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
char check = str.charAt(str.length()-1);
if(isValid(str, check)) {
System.out.print(process(str, check));
} else {
System.out.println("INVALID INPUT!");
}
sc.close();
}
private static boolean isValid(String str, char check) {
if(check!='.' && check!='!' && check!='?')
return false;
return true;
}
private static String process(String str, char check) {
String tokens[] = str.split("\\.|\\?|\\!|\\s|\\,");
String prefix = "\n", suffix = "";
int count = 0;
for(int index=0;index<tokens.length;index++) {
String word = tokens[index];
if(begEndVowel(tokens[index])) {
prefix += word + " ";
count++;
}
else
suffix += word + " ";
}
return "NUMBER OF WORDS BEGINNING AND ENDING WITH A VOWEL = " + count + prefix + suffix.trim() + check;
}
private static boolean begEndVowel(String word) { // To Check If A Word is to Start and End with a Vowel
int len = word.length();
char init = word.charAt(0);
if(len==1) {
return isVowel(init);
} else {
char fin = word.charAt(len-1);
return isVowel(init) && isVowel(fin);
}
}
private static boolean isVowel(char ch) {
String lis = "AEIOU";
if(lis.indexOf(ch)!=-1)
return true;
else
return false;
}
}