나는 대학을위한 그룹 프로젝트를 위해 돼지 라틴어 번역자를 만들었습니다. 우리는 실제로 번역기를 만들 필요가 없으며 우리가 원하는 어떤 식 으로든 문자열을 조작 할 수 있습니다. 나는 이것을 선택했다.)스캐너 클래스 : 단어로 음절 감지
가 내 번역기에 입력이 라틴기도가, 처음 두 행은 어느 있습니다 :
내가 다음 코드를 사용하여 내 번역기를 만든credo in unum deum
patrem omnipotentem
:
public static void pigLatinify(String fname) throws IOException
{
File file = new File("projectdata.txt");
try
{
Scanner scan1 = new Scanner(file);
while (scan1.hasNextLine())
{
Scanner scan2 = new Scanner(scan1.nextLine());
boolean test2;
while (test2 = scan2.hasNext())
{
String s = scan2.next();
char firstLetter = s.charAt(0);
if (firstLetter=='a' || firstLetter=='i' || firstLetter=='o' || firstLetter=='e' ||
firstLetter=='u' || firstLetter=='A' || firstLetter=='I' || firstLetter=='O' ||
firstLetter=='E' || firstLetter=='U')
{
String output = s + "hay" + " ";
System.out.print(output);
}
else
{
String restOfWord = s.substring(1);
String output = restOfWord + firstLetter + "ay" + " ";
System.out.print(output);
}
}
System.out.println("");
}
scan1.close();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
}
}
그것은 출력 처음 두 줄에 대해서 다음과 같은 결과를 얻었습니다.
redocay inhay unumhay eumday
atrempay omnipotentemhay
그러나 진정한 돼지 라틴어, 단음절 단어는 동일하게 유지되고 끝에 "-hay"가 추가되어 "it"가 "ithay"가되고 "egg"가 "egghay"가되지만 여러 음절 단어는 "-way"가 대신 끝에 추가됩니다. 그래서 "양궁"은 "궁도"가되고 "결말"은 "결말"이됩니다.
단어가 단음 문자인지 검색하는 데 Java (및 스캐너 클래스를 사용하는 방법)이 있습니까?
이 시점에서 나는 초급 프로그래머 일 뿐이라는 것을 지적 할 것입니다. 그렇기는하지만 매우 복잡하기 만하면됩니다.
관련 : [http://stackoverflow.com/a/405179/1225328](http://stackoverflow.com/a/405179/ 1225328) – sp00m