public class Quiz2 { public static void main(String[] args) { /* * 어린 제다이들은 요다와 대화하는 법을 배워야 한다 * 요다는 모든 문장에서 가장 앞 단어 두개를 제일 마지막에 말한다 * 어떤 문장이 주어졌을 때 요다의 말로 바꾸는 프로그램을 작성하세요 * * 입력) * 4 * I will go now to find the Wookiee * Sole found the death star near planet Kessel * I'll fight Darth Maul here and now * Vander will find Luke before he can escape * * go now to find the Wookiee I will * the death star near planet Kessel Sole found * Darth Maul here and now I'll fight * find Luke before he can escape Vander will */ Scanner sc = new Scanner(System.in); ArrayList<String> list = new ArrayList<String>(); ArrayList<String> acList = new ArrayList<String>(); System.out.println("입력 >> "); int num = sc.nextInt(); sc.nextLine();
for(int i = 0; i < num; i++) { System.out.println("문자열 입력 >> "); list.add(sc.nextLine()); }
for(String str : list) { String[] word = str.split(" "); if(word.length >= 2) { String first = word[0]; String second = word[1]; StringBuilder builder = new StringBuilder(); for(int i = 2; i < word.length; i++) { builder.append(word[i]).append(" "); } builder.append(first).append(" ").append(second); acList.add(builder.toString()); } }