1. 程式人生 > >java簡單陣列逆序

java簡單陣列逆序

import java.util.*;

public class 陣列逆序輸出 {
	public static void main(String[] args){
		Scanner input = new Scanner(System.in);
		
		System.out.println("輸入陣列的大小");
		int number = input.nextInt();
		String[] arr = new String[number];
		for(int i = 0; i <arr.length; i++){
			System.out.println("第"+(i+1)+"個元素:");
			arr[i] = input.next();
		}
		Arrays.sort(arr);
		for(int i = 0; i < arr.length; i++)
			System.out.print(arr[i]);
		System.out.println();
		for(int i = arr.length-1; i >= 0; i--)
			System.out.print(arr[i]);
	}
}