static int Q1(String word1, String word2) { // return the number of rhyming syll
ID: 3808569 • Letter: S
Question
static int Q1(String word1, String word2) {
// return the number of rhyming syllables between the two input words. We will define the number of rhyming
// syllables as the number of syllables in the largest matching suffix of sounds between the words. This
// is the same definition used by the provided library.
return //put answer here ;
}
public static void main(String[] args) {
}
}
could someone help me with this Java question
input: [capability, irritability]
Expected output : 4
input: [accelerometer, odometer]
Expected output : 3
Explanation / Answer
public class Ch
{
static int Q1(String word1, String word2) throws StringIndexOutOfBoundsException
{
int l=0;
int l1=word1.length(),l2=word2.length();
for(int i=l1-1,j=l2-1; i>0;j--,i--)
{
if(j>0&&i>0)
{
if(word1.charAt(i)==word2.charAt(j))
{
l++;
}
else
break;
}
}
return l-3;
}
public static void main(String[] args)
{
System.out.println(Ch.Q1("capability", "irritability"));
System.out.println(Ch.Q1("accelerometer", "odometer"));
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.