import java.util.*;
public class Lab04D
{
public static boolean startsWithVowel (String a)
{
String VOWELS = "aeiouAEIOU";
return (VOWELS.indexOf(a) != -1);
}
public static int findVowel(String str)
{
for (int i = 0; i < str.length(); i++)
{
if (startsWithVowel(str.charAt(i)))
{
return i;
}
}
return -1;
}
public static String piggy (String str)
{
int firstVowel = findVowel(str);
if (firstVowel <= 0) {
return str + "way";
}
else {
return str.substring(firstVowel, str.length()) +
str.substring(0,firstVowel) + "ay";
}
}
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("Please enter a sentence with 5 words:");
String str = input.nextLine();
//This is where I seperate the sentence into strings
int space = str.indexOf(" ");
String s1 = str.substring(0,space);
String s2 = str.substring(space+1);
int space2 = str.indexOf(" ");
String s3 = str.substring(0,space2);
String s4 = str.substring(space2+1);
int space3 = str.indexOf(" ");
String s5 = str.substring(0,space3);
String s6 = str.substring(space3+1);
int space4 = str.indexOf(" ");
String s7 = str.substring(0,space4);
String s8 = str.substring(space4+1);
System.out.println(" My Pig Latin Translator");
System.out.println(" by: Student Name Here");
System.out.println("Your original sentence is:"+str);
System.out.println("Your pig latin is: "+(piggy(s1))+" "+(piggy(s2))+" "+(piggy(s3))+" "+(piggy(s4)));
}
}
我试图翻译这句话但是当我输入例句“猪拉丁太酷了”时,我的输出是“igpay atinlay太酷了”。我该怎么做才能将这些单词分开,以便每个单词都被翻译出来?