需求:将用户输入的数组逆序输出。
import java.util.*; class Demo { public static void main(String[] args) { int[] arr = new int[10]; Scanner in = new Scanner(System.in); System.out.print("请输入十个整数,以回车键分隔:"); for (int i=0;i<arr.length ;i++ ) { arr[i] = in.nextInt(); } System.out.print("["); for (int i=arr.length-1;i>=0 ;i-- ) { if(i!=0) System.out.print(arr[i]+", "); else System.out.println(arr[i]+"]"); } } }