課程
/后端開發
/Java
/Java入門第一季(IDEA工具)升級版
怎么寫都不通過 能給個正確答案參考一下嗎
2016-12-04
源自:Java入門第一季(IDEA工具)升級版 2-4
正在回答
import java.util.Arrays;/*導入*/
public class HelloWorld {
? ? public static void main(String[] args) {
? ? ? ? int[] score={98,-23,64,91,199,52,73};//創建數組
? ? ? ? System.out.println("成績前三的成績為:");
? ? ? ? HelloWorld hello=new HelloWorld();//創建名為hello的對象
? ? ? ? hello.show(score);//調用方法傳輸成績的數組
? ? }
public void show(int[] score){
? ?Arrays.sort(score);//對score數組進行升序排序
? ?int count=0;//定義一個計數數量
? ? for(int i = score.length-1;i>=0;i--){//因為是升序所以從最后一個開始所以為int i = score.length-1; int i為最大值;i--依次遞減
? ? if(score[i]>100||score[i]<=0){//設定score大于100同時小于0的條件
? ? continue;//跳過
? ? count++;//count+1
? ? if(count>3){//定義跳出條件
? ? break;//跳出
? ? System.out.println(score[i]);//輸出答案
? }
}
舉報
0基礎萌新入門第一課,從Java環境搭建、工具使用、基礎語法開始
1 回答正確答案
3 回答秒采納,同學們請給個正確答案
6 回答參考答案出錯了。。。
5 回答求正確答案
1 回答正確答案就是這個
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2016-12-04
import java.util.Arrays;/*導入*/
public class HelloWorld {
? ? public static void main(String[] args) {
? ? ? ? int[] score={98,-23,64,91,199,52,73};//創建數組
? ? ? ? System.out.println("成績前三的成績為:");
? ? ? ? HelloWorld hello=new HelloWorld();//創建名為hello的對象
? ? ? ? hello.show(score);//調用方法傳輸成績的數組
? ? }
public void show(int[] score){
? ?Arrays.sort(score);//對score數組進行升序排序
? ?int count=0;//定義一個計數數量
? ? for(int i = score.length-1;i>=0;i--){//因為是升序所以從最后一個開始所以為int i = score.length-1; int i為最大值;i--依次遞減
? ? if(score[i]>100||score[i]<=0){//設定score大于100同時小于0的條件
? ? continue;//跳過
? ? }
? ? count++;//count+1
? ? if(count>3){//定義跳出條件
? ? break;//跳出
? ? }
? ? System.out.println(score[i]);//輸出答案
? }
? ? }
}