課程
/后端開發(fā)
/Java
/Java入門第一季(IDEA工具)
怎么優(yōu)化使得成績可以由用戶輸入啊,代碼怎么寫的
2019-05-07
源自:Java入門第一季(IDEA工具) 7-1
正在回答
使用Scanner
import java.util.Scanner;
public class HelloWorld {
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ?? ???Scanner input=new Scanner(System.int);
? ? ? ? int[] scores=new int[length];
? ? ? ? for(int i=0;i<scores.length;i++){
? ? ? ? scores[i]=input,nextInt(); ? ? ? ??
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? HelloWorld hello=new ?HelloWorld(); ?
? ? ? ? hello.three(scores);
? ? ? ? }
//定義方法完成成績排序并輸出前三名的功能
? ? public void three(int[] scores){
? ? ? ? int count=0;
? ? ? ? System.out.println("考試成績的前三名為:");
? ? ? ? Arrays.sort(scores);
? ? ? ? for(int i=scores.length-1;i>=0;i--){
? ? ? ? ? ? if(scores[i]>0&&scores[i]<100){
? ? ? ? ? ? ? ? System.out.println(scores[i]);
? ? ? ? ? ? ? ? count++;
? ? ? ? ? ? }
? ? ? ? ? ? if(count>=3){
? ? ? ? ? ? ? ? break;
}
慕斯卡8229098
使用系統(tǒng)提供的Scanner類。
舉報(bào)
0基礎(chǔ)萌新入門第一課,從Java環(huán)境搭建、工具使用、基礎(chǔ)語法開始
2 回答考試成績?nèi)绻猛獠枯斎氲脑挘a怎么實(shí)現(xiàn)
2 回答這個(gè)代碼怎么改就可以輸出前3名成績,謝謝
4 回答如果我用Scanner工具包自由輸入學(xué)生成績進(jìn)行有效成績排名該怎么做?
2 回答成績最高的前三名怎么得到
4 回答用有返回值的代碼怎么寫啊
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2019-05-07
使用Scanner
import java.util.Scanner;
public class HelloWorld {
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ?? ???Scanner input=new Scanner(System.int);
? ? ? ? int[] scores=new int[length];
? ? ? ? for(int i=0;i<scores.length;i++){
? ? ? ? scores[i]=input,nextInt(); ? ? ? ??
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? HelloWorld hello=new ?HelloWorld(); ?
? ? ? ? hello.three(scores);
? ? ? ? }
//定義方法完成成績排序并輸出前三名的功能
? ? public void three(int[] scores){
? ? ? ? int count=0;
? ? ? ? System.out.println("考試成績的前三名為:");
? ? ? ? Arrays.sort(scores);
? ? ? ? for(int i=scores.length-1;i>=0;i--){
? ? ? ? ? ? if(scores[i]>0&&scores[i]<100){
? ? ? ? ? ? ? ? System.out.println(scores[i]);
? ? ? ? ? ? ? ? count++;
? ? ? ? ? ? }
? ? ? ? ? ? if(count>=3){
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? }
}
2019-05-07
使用系統(tǒng)提供的Scanner類。