Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

2. The character \'Y\'ly\' can be considered a vowel if a word ends with \'Yly\'

ID: 3912708 • Letter: 2

Question

2. The character 'Y'ly' can be considered a vowel if a word ends with 'Yly', but a word is considered a consonant if it starts with 'Y'y. If a word starts and ends with 'Y'Py' it is also soncisdered a consonant. Given following matrix of type String that contains both vowels and consonants, implement the getConsonant method that returns only the words that are consonants. (10 points) String II) matrix "yellow", "game", "sky"), "yesterday", "yam", "main", ("y", "cry", "yank" Here is a method header. public StringlI getConsonant (StringlilII Array)t)

Explanation / Answer

Method:

public String[] getConsonant(String[][] Array)
{
int count = 0; //count total words
for(int i=0; i<Array.length; i++)
{
for(int j=0; j<Array[i].length; j++)
{
count++;
}
}

//declare new String array with size count
String[] consonant = new String[count];

count = 0; //set count to 0, acts as index

//examine each word
for(int i=0; i<Array.length; i++)
{
for(int j=0; j<Array[i].length; j++)
{
//if first letter is y/Y or last letter is not y/Y
if(Array[i][j].charAt(0)=='Y'||Array[i][j].charAt(0)=='y'||(Array[i][j].charAt(Array[i][j].length()-1)!='Y'&&Array[i][j].charAt(Array[i][j].length()-1)!='y'))
{
//add that string
consonant[count] = Array[i][j];
count++; //increment index
}
}
}

//new output array
String[] output =new String[count];

//move all strings to output array
for(int i=0; i<count; i++)
output[i] = consonant[i];

return output;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote