Skip to content

Commit

Permalink
Update PigLatin.java
Browse files Browse the repository at this point in the history
  • Loading branch information
MuhammadSiddiqui121 authored Jan 29, 2025
1 parent b632f6f commit 7852e09
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/main/java/PigLatin.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ public int findFirstVowel(String sWord) {
//precondition: sWord is a valid String of length greater than 0.
//postcondition: returns the position of the first vowel in sWord. If there are no vowels, returns -1
// your code goes here
String[] vowels = {"a", "e", "i", "o", "u"};
if(sWord.length() > 1 && sWord.substring(0, 2).equals("qu")) {
return -2;
}
for(int i = 0; i < sWord.length(); i++) {
for(int x = 0; x < vowels.length; x++) {
if(sWord.substring(i, i + 1).equals(vowels[x])) {
return i;
}
}
}

return -1;
}

Expand All @@ -41,8 +53,15 @@ public String pigLatin(String sWord) {
if(findFirstVowel(sWord) == -1) {
return sWord + "ay";
}
else {
return "ERROR!";
}
else if(findFirstVowel(sWord)==-2)
{
return sWord.substring(2,sWord.length())+"quay";
}
else if(findFirstVowel(sWord)==0)
return sWord + "way";
else return sWord.substring(findFirstVowel(sWord)) + sWord.substring(0, findFirstVowel(sWord)) + "ay";



}
}//end PigLatin class

0 comments on commit 7852e09

Please sign in to comment.