forked from Rishabh062/Hacktoberfest2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprog.java
113 lines (57 loc) · 1.88 KB
/
prog.java
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import java.util.*;
public class EachWordsVowelPrint
{
public static void main(String args[])
{
String st, word="";
char ch,ch1;
int v; // variable for vowel
int c; // variable for Consonents
int w; // variable for word
int i,j; // for loop
int l,l1; // l is for length of sentence and for word
v=c=w=0; // Initialization
Scanner sc=new Scanner(System.in);
System.out.println("Enter a sentence:");
st=sc.nextLine();
st=st + " "; // one space add to the sentence
//st=st.toUpperCase();
l=st.length(); // length of the sentence
for(i=0; i<l; i++)
{
ch=st.charAt(i);
// if space is come then goto else calculate each words vowel
if(ch!=' ')
{
word=word + ch;
}
else
{
l1=((word.trim()).length()); // length of the word
for(j=0; j<l1; j++)
{
ch1=word.charAt(j);
switch(ch1)
{
case 'A' :
case 'a' :
case 'E' :
case 'e' :
case 'I' :
case 'i' :
case 'O' :
case 'o' :
case 'U' :
case 'u' :
v++;
}
}
// print the word total vowels
System.out.println(word + " contain vowel= " + v);
// Initialize the words and v for vowel
word = "";
v=0;
}
}
}
}