[softeer] 8단 변속기 JAVA | 배열 초기화, else if

배열 초기화 :

int [] items = {1,2,3,4,5,6,7,8};

 

 

import java.util.*;
import java.lang.*;
import java.io.*;

// The main method must be in a class named "Main".
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int asc_nums[] = {1,2,3,4,5,6,7,8};
        int des_nums[] = {8,7,6,5,4,3,2,1};
        int cnt = 0;
        int des_cnt = 0;

        //오름차순인 경우
        for (int i=0; i<8; i++){
            int current = sc.nextInt();
            if (asc_nums[i] == current) cnt++;
            else if (des_nums[i] == current) des_cnt++;
        }
        if(cnt == 8) System.out.print("ascending");
        else if(des_cnt == 8) System.out.print("descending");
        else System.out.print("mixed");

        sc.close();
    }
}