forked from jwalapc/Your-Portfolio-website
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtempCodeRunnerFile.java
More file actions
71 lines (48 loc) · 1.95 KB
/
tempCodeRunnerFile.java
File metadata and controls
71 lines (48 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
65
66
67
68
69
70
71
import java.io.*;
public class vowelword
{
public static void main(String arg[])throws IOException
{
int l,i,n, p, nowwv;
boolean flag = true;
char ch, fc, lc, lastChar;
String str, prefix = "", suffix = "";
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a sentence : ");
str = br.readLine();
l = str.length();
lastChar = str.charAt(l-1); // Extract the last character
if(lastChar != '.' && lastChar != '?' && lastChar != '!')
System.out.println("INVALID INPUT");
else{
//Pointer to the first character of each word
p = 0;
// store no of words starting and ending with a vowel
nowwv = 0;
for(i = 0; i < l; i++){
ch = str.charAt(i);
if(ch == ' ' || ch == '?' || ch == '!' || ch == '.'){
//Check if first and last character of the word is a vowel
if(isVowel(str.charAt(p)) && isVowel(str.charAt(i-1))){
//Add words starting and ending with a vowel
prefix += str.substring(p,i) + " ";
nowwv++;
}else{
//Add words that doesn't start and end with a vowel
suffix += str.substring(p,i) + " ";
}
p = i + 1;
}//if
}//for loop
System.out.println("NUMBER OF WORDS BEGINNING AND ENDING WITH A VOWEL = " + nowwv);
System.out.println(prefix + suffix);
}//else
}//end of main
//Return true if 'ch' is a vowel else returns false
private static boolean isVowel(char ch){
if(ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U')
return true;
else
return false;
}//end of isVowel
}//end of class