class
GFG
{
static
boolean
isVowel(
char
ch)
{
return
( ch ==
'a'
|| ch ==
'e'
||
ch ==
'i'
|| ch ==
'o'
||
ch ==
'u'
);
}
static
int
calcDiff(String str)
{
int
count_vowels =
0
, count_conso =
0
;
int
hard_words =
0
, easy_words =
0
;
int
consec_conso =
0
;
for
(
int
i =
0
; i < str.length(); i++)
{
if
(str.charAt(i) !=
' '
&& isVowel(Character.toLowerCase(str.charAt(i))))
{
count_vowels++;
consec_conso =
0
;
}
else
if
(str.charAt(i)!=
' '
)
{
count_conso++;
consec_conso++;
}
if
(consec_conso ==
4
)
{
hard_words++;
while
(i < str.length() && str.charAt(i)!=
' '
)
i++;
count_conso =
0
;
count_vowels =
0
;
consec_conso =
0
;
}
else
if
( i < str.length() &&
(str.charAt(i) ==
' '
|| i == str.length()-
1
))
{
if
(count_conso > count_vowels)
hard_words++;
else
easy_words++;
count_conso =
0
;
count_vowels =
0
;
consec_conso =
0
;
}
}
return
5
* hard_words +
3
* easy_words;
}
public
static
void
main (String[] args)
{
String str =
"I am a geek"
;
String str2 =
"We are geeks"
;
System.out.println(calcDiff(str));
System.out.println(calcDiff(str2));
}
}