문제

quiz

  • 입력한 숫자 역순 출력




코드

Main.java

package pack_CusCls06;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		System.out.print("배열 크기 설정 : ");
		int size = scanner.nextInt();
		System.out.printf("입력하실 숫자 %d개를 입력해주세요 : ", size);
		double[] arr = new double[size];		
		for (int i = 0; i < arr.length; i++) {
			arr[i] = scanner.nextDouble();
		}
		
		Arr arr2 = new Arr(arr);	

		arr2.mtdArr();
		
		scanner.close();

	}

}

Arr.java

package pack_CusCls06;

public class Arr {
	
	private double[] arr;

	public Arr(double[] arr) {
		this.arr = arr;
	}
	
	public void mtdArr() {
		System.out.print("입력하신 숫자들의 역순 : ");
		for (int i = arr.length-1; 0 <= i; i--) {
			System.out.print(arr[i] + "  ");
		}
	}

}


결과

quiz

Leave a comment