왕초보 LECTURE 자바소스 확인 부탁드려요~

  • hn
    hn

    왕초보급 [LECTURE] 구현 문제인데....
    LECTURE

    처음 입력받은 숫자만큼 입력받고 출력시켜주는데,
    어떤 부분이 오답인건지 모르겠습니다.
    허접한 소스지만.. 한 번 봐주세요!

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.ArrayList;
    import java.util.Scanner;
    
    public class Main {
    
        public static void main(String[] args) throws IOException {
    
            Scanner index = new Scanner(System.in);
            int temp; 
            int cnt = 0;
            int indexValue = index.nextInt();
    
            BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
            String inputValue;
            String changeValue;
            String[] finalValue;
            String sumValue = "";
    
            for (int i = 0; i < indexValue; i++) {
    
                inputValue = input.readLine();
    
                temp = inputValue.length();
    
                if ( (temp%2) == 0){
                    finalValue = new String[temp/2];
    
                    int k = 0;
                    for (int j = 0; j < temp; j++) {
                        finalValue[k] = inputValue.substring(j, j+2);
                        k ++;
                        j ++;
                    }
    
                    for (int j = finalValue.length; j > 0; j--) {
                        for (int h = 0; h < j-1; h++) {
                            if (finalValue[h].compareTo(finalValue[h+1]) > 0) {
                                changeValue = finalValue[h];
                                finalValue[h] = finalValue[h+1];
                                finalValue[h+1] = changeValue;
                            }
                        }
                    }
    
                    for (int j = 0; j < finalValue.length; j++) {
                        cnt++;
                        sumValue += finalValue[j];
                        if (cnt == finalValue.length) {
                            sumValue += "\n";
                            cnt = 0;
                        }
                    }
                }else{
                    break;
                }
    
            }
            System.out.println(sumValue);
    
        }
    
    }
    


    7년 전
1개의 댓글이 있습니다.
  • hyunhwan
    hyunhwan

    Scanner나 BufferedReader중 하나만 사용을 하셔야 할 것 같습니다.


    7년 전 link
  • 정회원 권한이 있어야 커멘트를 다실 수 있습니다. 정회원이 되시려면 온라인 저지에서 5문제 이상을 푸시고, 가입 후 7일 이상이 지나셔야 합니다. 현재 문제를 푸셨습니다.