我正在嘗試將您的句子翻譯成拉丁語的程序。下面的代碼我到目前爲止:豬拉丁語句子轉換器
public class PigLatin {
public static void main(String[] args) {
//Enter text in the quotes of System.ot.println(covertToLatin(" "));
System.out.println(covertToLatin("Type your sentence here."));
}
private static String covertToLatin(String string) {
String end = "";
String delims = "\\s+";
String[] words = string.split(delims);
for (int i = 0; i < words.length; i++) {
if(isVowel(words[i].toLowerCase().charAt(0))) {
end += words[i] + "ay";
} else {
end += words[i].substring(1) + words[i].substring(0, 1) + "ay";
}
}
return end;
}
private static boolean isVowel(char c) {
if (c == 'a')
return true;
if (c == 'e')
return true;
if (c == 'i')
return true;
if (c == 'o')
return true;
if (c == 'u')
return true;
return false;
}
}
它翻譯「在這裏輸入你的句子。」 to「ypeTayouryayentencesayere.hay」我很難找到一種方法來翻譯我的整個句子。你能幫我把整句翻譯成拉丁文嗎?另外,如果你能找到一種方法讓句子在所有大寫字母上轉換,它也會有所幫助。
對不起,我很困惑你的問題是什麼,什麼不是你想要的? –
它不工作,只是沒有空格?如果我清理你的輸出,這是合理的拉丁語:'ypeTay ouryay entencesay ere.hay'。我認爲你只需要在單詞之間添加空格。 – Ian
它看起來像你的結果幾乎是正確的,除了一些缺陷。你應該能夠解決這些問題。 – ajb