JJ プログラム仙人修行日誌

2024/04/20 からは、プログラム仙人修行の日誌を書いてます。

gg118.java

class gg118 {
    public static void main(String[] args) {

        int [] ringo = { 2, 4, 5, 1, 3};
        int n = ringo.length; // n = ringo.lenght - 1 は,やめた

        for(int i = 1; i < n ; i++){
            for(int j = i-1; j >=0; j--){
                if(ringo[j] > ringo[j+1]){
                    int temp = ringo[j];
                    ringo[j] = ringo[j+1];
                    ringo[j+1] = temp;
                }else{
                    break;
                }
            }
        }

//整列済みを表示
        for(int i=0; i < n; i++){
            System.out.print(ringo[i] + ", ");
        }
    }
}