上一章我们将到数组通过方法的接收,所改变的都保留下来。接下来我们讲到数组的定义排序。
public class qvod3
{
public static void main(String args[]){
int score[]={67,89,87,69,90,100,75,90};
int age[]={31,30,18,17,8,9,1,39};
sort(score);
print(score);
System.out.print("\n");
sort(age);
print(age);
}
public static void sort(int temp[]){ //数组排序
for (int i=1;i<temp.length ;i++)
{
for (int j=0;j<temp.length ;j++ )
{
if(temp[i]<temp[j]){
int x =temp[i];
temp[i] = temp[j];
temp[j] =x;
}
}
}
}
public static void print(int temp[]){
for (int i =0;i<temp.length ;i++ )
{
System.out.print(temp[i]+"\t");
}
}
}
由此可见,任何的语句都可以使用方法调用输出。