백준 2920번 음계 자바 질문
조회수 365회
안녕하세요 자바 공부를 시작한 학생입니다. 코드에서 오류는 나지 않는데 결과가 출력되지 않습니다. 어디서 잘못 된 건가요!? public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); ArrayList arr = new ArrayList<>();
while (st.hasMoreTokens()) {
arr.add(Integer.parseInt((st.nextToken())));
}
while (st.hasMoreTokens()) {
int i = 0;
if (arr.indexOf(i) == arr.indexOf(i) - 1) {
System.out.println("ascending");
i++;
}
else if (arr.indexOf(i) == arr.indexOf(i) + 1) {
System.out.println("descending");
i++;
}
else {
System.out.println("mixed");
}
}
}
}
1 답변
-
코드가 오류가 난게 아니라면 틀린게 없다는소리인데 while문에서 그냥 통과되는거같네요 한번 첫번째 while 문과 두번째 while 문을 로그를 찍어보세요
while (st.hasMoreTokens()) { //1.로그찍을곳1 arr.add(Integer.parseInt((st.nextToken()))); //2.로그찍을곳2 } while (st.hasMoreTokens()) { //3.로그찍을곳3 int i = 0; if (arr.indexOf(i) == arr.indexOf(i) - 1) { System.out.println("ascending"); i++; } else if (arr.indexOf(i) == arr.indexOf(i) + 1) { System.out.println("descending"); i++; } else { System.out.println("mixed"); } }
}
//로그찍을곳1 : 안나오는경우 while문의 조건이 해당x //로그찍을곳2 : 로그찍을곳1 은나오지만 로그찍을곳2가안나오는경우 while 문의 조건이 해당되지만 ArrayList 에 안들어가짐 //로그찍을곳3 : 로그찍을곳1과로그찍을곳2는 나오지만 3이안나오는경우 두번재 while문 조건이 해당x
-
(•́ ✖ •̀)
알 수 없는 사용자
-
댓글 입력