第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

麻煩大佬幫忙看看問(wèn)題出在哪了

為什么我最后輸出的是最小的三個(gè),而且該剔除的數(shù)據(jù)沒(méi)有剔除。。。。在線求大佬解答

import java.util.Arrays;
public class HelloWorld {
//完成 main 方法
??? public static void main(String[] args) {
??? int[] scores={89,-23,64,91,119,52,73};?? ?
??? HelloWorld hello=new HelloWorld();
? ?
??? System.out.println("考試成績(jī)的前三名為:");?? ?
??? hello.topThree(scores);?? ?
? ?
??? }
??? //定義方法完成成績(jī)排序并輸出前三名的功能
??? public void topThree(int[] scores){
??????? Arrays.sort(scores);
??????? for(int i=scores.length-1;i>=0;i--){
??????????? if(scores[i]<0||scores[i]>100)
??????????? continue;
??????? }
?? ?
?????? ?
?? ?
??????? for(int j=0;j<=2;j++){
??????????? System.out.println(scores[j]);
??????? }
??? }
? ?
}http://img1.sycdn.imooc.com//5efc1ef80001f64810510626.jpg

正在回答

4 回答

大佬,要不這樣:

package java12;

import java.util.Arrays;

public class HelloWorld {

//完成 main 方法

? ? public static void main(String[] args) {

? ? int[] scores = {89,-23,64,91,119,52,73};? ??

? ? HelloWorld hello = new HelloWorld(); ? ?

? ? System.out.println("考試成績(jī)的前三名為:");? ??

? ? hello.topThree(scores);? ? ? ?

? ? }

? ? //定義方法完成成績(jī)排序并輸出前三名的功能

? ? public void topThree(int[] scores){

? ? ? ? Arrays.sort(scores);

? ? ? ? int count = 0;

? ? ? ? for(int i = scores.length - 1;i >= 0;i--){

? ? ? ? ? ? if(scores[i] < 0 ||scores[i] > 100)

? ? ? ? ? ? {

? ? ? ? ? ? continue;

? ? ? ? ? ? }

? ? ? ? ? ? else{

? ? ? ? ? ? System.out.println(scores[i]);

? ? ? ? ? ? count++;

? ? ? ? ? ? if(count >= 3) break;

? ? ? ? ? ? }

? ? ? ? } ? ??

? ? }

}

http://img1.sycdn.imooc.com//5f0466c90001f1b608400771.jpg


1 回復(fù) 有任何疑惑可以回復(fù)我~

哈哈,我竟然看懂了

0 回復(fù) 有任何疑惑可以回復(fù)我~

首先continue是跳出本次循環(huán),那么你第一個(gè)for就毫無(wú)用處,你可以設(shè)置為超過(guò)限制的數(shù)變成一個(gè)負(fù)數(shù),比如負(fù)一(如果是找最小的幾個(gè)數(shù),那么定義為大于100的數(shù),比如101)

另外,sort是從小到大排序,所以如果你想找到最小,那么可以直接從scores[0]開(kāi)始,采用i++,去找最小的三個(gè),但是如果想找最大的,可以從scores.length - 1開(kāi)始,采用i--去找最大的三個(gè)(當(dāng)然還有個(gè)笨辦法是創(chuàng)建一個(gè)新數(shù)組,讓新數(shù)組的length-1等于scores[0],以此類推)

1 回復(fù) 有任何疑惑可以回復(fù)我~

sort是從小到大排序,所以你輸出的是最小的3個(gè)。

而且continue的作用只是跳出本次循環(huán),不是剔除數(shù)據(jù)。

1 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
Java入門(mén)第一季(IDEA工具)升級(jí)版
  • 參與學(xué)習(xí)       1167313    人
  • 解答問(wèn)題       18483    個(gè)

0基礎(chǔ)萌新入門(mén)第一課,從Java環(huán)境搭建、工具使用、基礎(chǔ)語(yǔ)法開(kāi)始

進(jìn)入課程

麻煩大佬幫忙看看問(wèn)題出在哪了

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)