본문 바로가기

자료구조&알고리즘/알고리즘-문제풀이

[코드업 기초100제] 1094-[기초-1차원배열] 이상한 출석 번호 부르기2

정보 선생님은 수업을 시작하기 전에 이상한 출석을 부른다.

학생들의 얼굴과 이름을 빨리 익히기 위해 번호를 무작위(랜덤)으로 부르는데,
영일이는 선생님이 부른 번호들을 기억하고 있다가 거꾸로 불러보는 것을 해보고 싶어졌다.

출석 번호를 n번 무작위로 불렀을 때, 부른 번호를 거꾸로 출력해 보자.

 

import java.util.Scanner;

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

		Scanner scan = new Scanner(System.in);
		
		int count = scan.nextInt();
		
		int[] students = new int[count];
		int numbers = 0;
		for (int i = 0; i < count; i++) {
			numbers = scan.nextInt();
			students[i] = numbers;
		}
		
		for (int j = students.length -1; j >= 0; j--) {
			System.out.printf("%d ", students[j]);
		}
		
	}
	
}
반응형