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