"Program 40"
Title: Output an array in reverse order.
1. Procedure analysis: With the first and the last exchange.
2. Program Source code:
1 Importjava.util.Arrays;2 ImportJava.util.Random;3 4 /**5 *6 * "program 40"7 * Title: Output an array in reverse order. 8 * Program Analysis: First with the last exchange, and the second with the last second exchange, so loop. 9 *Ten * @authorwww.cnblogs.com/java-100 One * A */ - - Public classJAVA40 { the - Public Static voidMain (string[] args) { - int[] arr =New int[20]; -Random ran =NewRandom (); + for(inti = 0; i < arr.length; i++) { -Arr[i] = ran.nextint (100); + } A System.out.println (arrays.tostring (arr)); at for(inti = 0; i < ARR.LENGTH/2; i++) { - inttemp =Arr[i]; -Arr[i] = arr[arr.length-i-1]; -Arr[arr.length-i-1] =temp; - } - System.out.println (arrays.tostring (arr)); in } - to}
Java rewrite "C Classic 100 Questions"--40