java入門第一季中,7-6的練習怎么寫代碼?。空埓笊駧蛶兔?!
3 回答
已采納
望遠
TA貢獻1017條經驗 獲得超1032個贊
import?java.util.Arrays;
public?class?HelloWorld?{
????public?static?void?main(String[]?args)?{
HelloWorld?hello?=?new?HelloWorld();
int[]?scores={79,52,98,81};
????????
//調用方法,傳入成績數(shù)組,并獲取成績的個數(shù)
int?count=hello.sort(scores);
System.out.println("共有"+count+"個成績信息!");
}
????
/*
?*?功能:將考試成績排序并輸出,返回成績的個數(shù)
?*?定義一個包含整型數(shù)組參數(shù)的方法,傳入成績數(shù)組
?*?使用Arrays類對成績數(shù)組進行排序并輸出
?*?方法執(zhí)行后返回數(shù)組中元素的個數(shù)
?*/
public?int?sort(??int[]?scores???){
Arrays.sort(scores);
System.out.println(Arrays.toString(scores));
return?scores.length;
????????//返回數(shù)組中元素的個數(shù)
????????
}
}點擊展開后面7條
添加回答
舉報
0/150
提交
取消
