import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int[] nums = new int[10]; for (int i = 0; i < nums.length; i++) { nums[i] = in.nextInt(); } for (int i = nums.length-1; i >= 0; i--) { System.out.print(nums[i] + " "); } } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String[] str = in.nextLine().split(" "); StringBuilder sb = new StringBuilder(); for(int i = str.length - 1; i >= 0; i--) { sb.append(str[i] + " "); } System.out.println(sb.toString()); } }
String数组的逆序
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 while (in.hasNextLine()) { // 注意 while 处理多个 case String[] str = in.nextLine().split(" "); reverse(str); for(String s:str){ System.out.printf("%s ",s); } } } private static void reverse(String[] str){ for(int i=0;i<str.length/2;i++){ String temp = str[i]; str[i] = str[str.length-i-1]; str[str.length-i-1]=temp; } } }
import java.util.Scanner; import java.util.ArrayList; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); ArrayList<Integer> array=new ArrayList<Integer>(); while (in.hasNextInt()) { // 注意 while 处理多个 case int a = in.nextInt(); array.add(a); } if(array.size()==10){ for(int i=9;i>=0;i--){ System.out.print(array.get(i)+" "); } } } }
import java.util.Scanner ; public class Main{ public static void main(String[] args){ int[] a = new int[11] ; Scanner scanner = new Scanner(System.in); for(int i = 0 ; i < 10 ; i ++){ a[i] = scanner.nextInt(); } for(int i = 9 ; i >= 0 ; i -- ){ System.out.print(a[i]+" ") ; } } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] arr = new int[10]; for (int i = 0; i < 10; i++) { arr[i] = sc.nextInt(); } for (int j = 9; j >= 0; j-- ) { System.out.print(arr[j]+" "); } } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while(scanner.hasNext()){ int[] toArr = new int[10]; //StringBuffer strBuff = new StringBuffer(str); for(int i = 0;i < 10;i++){ toArr[i] = scanner.nextInt(); } for(int j = toArr.length - 1;j >= 0;j--){ System.out.print(toArr[j] + " "); } } } }
import java.util.*; public class Main{ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int[] arr = new int[10]; for (int i = 0; i < arr.length; i++) { arr[i] = scanner.nextInt(); } for (int i = arr.length-1; i >= 0 ; i--) { System.out.print(arr[i]+" "); } } }