如何编写一个程序:从键盘中输入一串整数保存到数组中,调用函数antitone()将数组反

如题所述

第1个回答  2011-05-09
package a.b.c;

import java.util.Scanner;

public class Test {

public static void main(String [] args){

Scanner input = new Scanner(System.in);

System.out.println("How many integers you want to input");
int num = input.nextInt();
int [] array = new int[num];
int i = 0;
while(i<num){
array[i] = input.nextInt();
i++;
}

int [] array2 = new Test().antitone(array);
for(int j=0;j<num;j++){
System.out.println(array2[j]);
}
}

public int [] antitone(int [] arr){
int temp;
int len = arr.length;
for(int i=0;i<len/2;i++){
temp = arr[i];
arr[i] = arr[len-1-i];
arr[len-i-1] = temp;
}

return arr;
}
}本回答被网友采纳
相似回答