输入数组,最大的与第一个元素交换,最小的与最后一个元素交换,输出数组。 用JAVA做
public class test4 {
/**
*
*/
public static void main(String[] args) {
int min,max;
Scanner input=new Scanner(System.in);
System.out.print("请输入数组的长度:");
int num=input.nextInt();
int[] score=new int[num];
for(int i=0;i<num;i++){
System.out.print(i+1+":");
score[i]=input.nextInt();
}
max=score[0];
for(int index=0;index<score.length;index++){
if(score[index]>max){
max=score[index];
}
}
System.out.println("最大的数为:"+max);
min=score[0];
for(int j=0;j<score.length;j++){
if(score[j]<min){
min=score[j];
}
}
System.out.println("最小的数为:"+min);
int m,n;
for(int index2=0;index2<score.length;index2++){
m=max;
score[0]=max;
m=score[0];
System.out.println(score[index2]);
}
}
}
我写不下了,能否扩充下??!
根本无法看懂,能否加上解释