課程
/后端開發
/Java
/Java入門第一季(IDEA工具)升級版
怎么優化使得成績可以由用戶輸入啊,代碼怎么寫的
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
使用系統提供的Scanner類。
舉報
0基礎萌新入門第一課,從Java環境搭建、工具使用、基礎語法開始
2 回答考試成績如果用外部輸入的話,代碼怎么實現
2 回答這個代碼怎么改就可以輸出前3名成績,謝謝
4 回答如果我用Scanner工具包自由輸入學生成績進行有效成績排名該怎么做?
2 回答成績最高的前三名怎么得到
4 回答用有返回值的代碼怎么寫啊
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
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
使用系統提供的Scanner類。