上一章我們將到數組通過方法的接收,所改變的都保留下來。接下來我們講到數組的定義排序。
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");
}
}
}
由此可見,任何的語句都可以使用方法調用輸出。