Question: Hi this is my code for the following task. Specification: Main class: StretchWith 2 Vowels Read sentences from the user until * is entered. Show
Hi this is my code for the following task.
Specification:
Main class: StretchWithVowels
Read sentences from the user until is entered. Show the number of words in each sentence that contain a stretch of nonz characters with exactly vowels. A stretch starts from the start of the word or after a z A stretch terminates just before another z or at the end of the word.
Examples:
Matching words: zoo, azozooza, GONZALEZ
Nonmatching words: ozo, azoooza
The sentences contain no punctuation, the words are separated by one or more spaces, and the characters may be upper or lower case. Keep reading sentences until the user enters
Sample IO:
Sentence: azoooza azooza zoo azoo
Matching words
Sentence: GONZALEZ passes the ball to VAZQUEZ
Matching words
Sentence: azozototzeti
Matching words
Sentence:
Done
MY CODE
import java.util.Scanner;
public class StretchWithVowels
public static void mainString args
Scanner sc new ScannerSystemin;
while true
int count ;
System.out.printSentence: ;
String sentence scnextLine;
if sentenceequals
System.out.printlnDone;
break;
String words sentence.splits;
for String word : words
if hasTwoVowelsInStretchword
count;
System.out.printlnMatching words count;
scclose;
static boolean hasTwoVowelsInStretchString word
boolean inStretch false;
int vowelCount ;
for char ch : word.toCharArray
if CharactertoLowerCasechz
inStretch true; Set inStretch when encountering z
else if inStretch
char lowercaseCh Character.toLowerCasech;
if lowercaseCh a lowercaseCh e lowercaseCh i lowercaseCh o lowercaseCh u
vowelCount;
if vowelCount
return false; More than vowels in stretch, not a match
else
vowelCount ; Reset vowel count when not in stretch
return vowelCount ;
This is a split difference of my vs the correct output
DIFF SPLIT DIFF YOUR OUTPUT EXPECTED
Sentence: GONZALEZ passes the ball to VAZQUEZ
Sentence: GONZALEZ passes the ball to VAZQUEZ
Matching words
Sentence: azozotoezeti
Matching words
Sentence: azozotoezeti
Matching words
Sentence: azoooza azOtOza zoo AZoo
Matching words
Sentence: azoooza azOtOza zoo AZoo
Matching words
Sentence: ooze zeez zaap zapa zaza
Sentence: ooze zeez zaap zapa zaza
Matching words
Sentence:
Done
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
