Java 中帶參帶返回值方法的使用
阿新 • • 發佈:2017-06-06
public java //System.out.println("共有"+count+"個成績信息!");
public class mains {
public static void main(String[] args) {
mains hello = new mains();
int[] scores={79,52,98,81};
hello.sort(scores);
System.out.println("第一"+hello.sort(scores));
//調用方法,傳入成績數組,並獲取成績的個數
//int count= hello.sort(scores);
// System.out.println(hello.sort(scores));
}
/*
* 功能:將考試成績排序並輸出,返回成績的個數
* 定義一個包含整型數組參數的方法,傳入成績數組
* 使用Arrays類對成績數組進行排序並輸出
* 方法執行後返回數組中元素的個數
*/
public int sort(int scores[]){
Arrays.sort(scores);
System.out.println("第二"+Arrays.toString(scores));
//返回數組中元素的個數
return 1;
}
}
Java 中帶參帶返回值方法的使用