倒置数组 Exercise07_12

 1 import java.util.Scanner;
 2 /**
 3  * @author 冰樱梦
 4  * 时间:2018年下半年
 5  * 题目:倒置数组
 6  *
 7  */
 8 public class Exercise07_12 {
 9     public static void main(String[] args){
10         Scanner input=new Scanner(System.in);
11         double[] array=new double[10];
12         System.out.println("Enter 10 numbers: ");
13         for(int i=0;i<array.length;i++){
14             array[i]=input.nextDouble();
15         }
16         for(double a:reverse(array)){
17             System.out.println(a);
18         }
19         
20     }
21     
22     //倒置数组
23     public static double[] reverse(double[] array){
24         double[] list=new double[array.length];
25         for(int i=0,j=list.length-1;i<list.length;i++,j--){
26             list[j]=array[i];
27         }
28         return list;
29     }
30 }
原文地址:https://www.cnblogs.com/cherrydream/p/10174094.html