課程
/后端開發(fā)
/Java
/Java入門第一季(IDEA工具)升級(jí)版
這邊報(bào)錯(cuò)好像是輸出地方錯(cuò)了!
2018-07-21
源自:Java入門第一季(IDEA工具)升級(jí)版 7-1
正在回答
public class MyJob{
? ?//完成 main 方法
? ?public static void main(String[] args) {
? ? ? ?int[] scores={89,-23,64,91,119,52,73};
? ? ? ?System.out.println("考試前三名:");
? ? ? ?MyJob hello=new MyJob();
? ? ? ?hello.numShow(scores);
? ?}
? ?//定義方法完成成績排序并輸出前三名的功能
? ?public void numShow(int[] scores){
? ? Arrays.sort(scores);
? ? int count=0;
? ? for(int i=(scores.length-1);i>=0;i--){
? ? if(scores[i]>100||scores[i]<0){
? ? continue;
? ? }
? ? count++;
? ? if(count>3){
? ? break;
? ? System.out.println(scores[i]);
? ?} ? ?
}
public?class?MyJob{ ???//完成?main?方法 ???public?static?void?main(String[]?args)?{ ???????int[]?scores={89,-23,64,91,119,52,73}; ???????System.out.println("考試前三名:"); ???????MyJob?hello=new?MyJob(); ???????hello.numShow(scores); ???} ???//定義方法完成成績排序并輸出前三名的功能 ???public?void?numShow(int[]?scores){ ??? Arrays.sort(scores); ??? int?count=0; ??? for(int?i=(scores.length-1);i>=0;i--){ ??? if(scores[i]>100||scores[i]<0){ ??? continue; ??? } ??? ?count++; ??? if(count>3){ ??? break; ??? } ??? System.out.println(scores[i]); ??? } ???}???? }
import java.util.Arrays;public class HelloWorld {??? ??? //完成 main 方法??? public static void main(String[] args) {?????? ??????? System.out.println("考試成績的前三名為:");?? ??? //定義方法完成成績排序并輸出前三名的功能??? ??? int[] scores={89,-23,64,91,119,52,73};??? Arrays.sort(scores);? ????? int num=0;??????? for(int i=scores.length-1;i>=0;i--){??????????? ??????????? if (scores[i]<0 ||? scores[i]>100){??????????????? continue;??????????? }?????????????? num++;?????????????? if (num>3){?????????????????? break;?????????????? }??????????????? ??????????????? System.out.println(scores[i]);??????????????? ??????????? }?????? ??? ??????? }??? ??? }??? ???
我只能改成這樣了
最后面輸出里改為scores[scores.length-1]
另外,你的for循環(huán)和后面輸出一點(diǎn)關(guān)系沒有
噢。不好意思,看錯(cuò)了
for循環(huán)里的i<scores.length后面應(yīng)該減1,因?yàn)閿?shù)組長度為7,不然當(dāng)你下面的scores[7]的時(shí)候就超索引了
舉報(bào)
0基礎(chǔ)萌新入門第一課,從Java環(huán)境搭建、工具使用、基礎(chǔ)語法開始
4 回答各位大神,幫我看看是哪里錯(cuò)了?謝謝
1 回答各位大佬,能幫我看看哪錯(cuò)了嗎?
3 回答請各位大神幫忙看下這是哪里錯(cuò)了,感謝
3 回答我錯(cuò)哪了,麻煩指出,謝謝
6 回答各位大佬,到底是哪里出錯(cuò)了,幫忙看看,謝謝
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)
2018-07-30
public class MyJob{
? ?//完成 main 方法
? ?public static void main(String[] args) {
? ? ? ?int[] scores={89,-23,64,91,119,52,73};
? ? ? ?System.out.println("考試前三名:");
? ? ? ?MyJob hello=new MyJob();
? ? ? ?hello.numShow(scores);
? ?}
? ?//定義方法完成成績排序并輸出前三名的功能
? ?public void numShow(int[] scores){
? ? Arrays.sort(scores);
? ? int count=0;
? ? for(int i=(scores.length-1);i>=0;i--){
? ? if(scores[i]>100||scores[i]<0){
? ? continue;
? ? }
? ? count++;
? ? if(count>3){
? ? break;
? ? }
? ? System.out.println(scores[i]);
? ? }
? ?} ? ?
}
2018-07-30
2018-07-24
import java.util.Arrays;
public class HelloWorld {
???
??? //完成 main 方法
??? public static void main(String[] args) {
??????
??????? System.out.println("考試成績的前三名為:");
??
??? //定義方法完成成績排序并輸出前三名的功能
???
??? int[] scores={89,-23,64,91,119,52,73};
??? Arrays.sort(scores);
?
????? int num=0;
??????? for(int i=scores.length-1;i>=0;i--){
???????????
??????????? if (scores[i]<0 ||? scores[i]>100){
??????????????? continue;
??????????? }
?????????????? num++;
?????????????? if (num>3){
?????????????????? break;
?????????????? }
???????????????
??????????????? System.out.println(scores[i]);
???????????????
??????????? }
??????
???
??????? }
???
??? }
???
???
2018-07-22
我只能改成這樣了
2018-07-21
最后面輸出里改為scores[scores.length-1]
另外,你的for循環(huán)和后面輸出一點(diǎn)關(guān)系沒有
2018-07-21
噢。不好意思,看錯(cuò)了
2018-07-21
噢。不好意思,看錯(cuò)了
2018-07-21
for循環(huán)里的i<scores.length后面應(yīng)該減1,因?yàn)閿?shù)組長度為7,不然當(dāng)你下面的scores[7]的時(shí)候就超索引了