/* 배열 뒤집기
* 정수가 들어 있는 배열 num_list가 매개변수로 주어집니다.
* num_list의 원소의 순서를 거꾸로 뒤집은 배열을 return
*
* num_list result
* [1, 2, 3, 4, 5] [5, 4, 3, 2, 1]
* [1, 1, 1, 1, 1, 2] [2, 1, 1, 1, 1, 1]
* [1, 0, 1, 1, 1, 3, 5] [5, 3, 1, 1, 1, 0, 1]
*/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | public class programmer_0_51 { static int[] a1 = {1, 2, 3, 4, 5}; static int[] a2 = {1, 1, 1, 1, 1, 2}; static int[] a3 = {1, 0, 1, 1, 1, 3, 5}; public int[] solution(int[] num_list) { int[] answer = new int[num_list.length]; int idx = 0; for(int i = num_list.length-1; i >= 0; i--){ answer[idx] = num_list[i]; idx++; } for(int i : answer) System.out.println(i); return answer; } public static void main(String args[]){ programmer_0_51 t = new programmer_0_51(); System.out.println("---------------------------------------"); System.out.println("result = " + t.solution(a1)); System.out.println("---------------------------------------"); System.out.println("result2 = " + t.solution(a2)); System.out.println("---------------------------------------"); System.out.println("result3 = " + t.solution(a3)); System.out.println("---------------------------------------"); } } | cs |