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

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

請(qǐng)問怎么沒辦法輸出前三名,是方法哪里寫錯(cuò)了

package grade;


import java.util.Arrays;


/*1、 考試成績(jī)已保存在數(shù)組 scores 中,數(shù)組元素依次為 89 , -23 , 64 , 91 , 119 , 52 , 73


2、 要求通過自定義方法來實(shí)現(xiàn)成績(jī)排名并輸出操作,將成績(jī)數(shù)組作為參數(shù)傳入


3、 要求判斷成績(jī)的有效性( 0—100 ),如果成績(jī)無效,則忽略此成績(jī)*/


public class one{

public void grade(int []grades) {

Arrays.sort(grades);

int[] G = new int[3];

int j = 0,q = 0;

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

if(grades[i] >0 && grades[i] < 100) {

? ?G[q] = grades[i];

? q++;

? j++;

}

?

if(j > 3) break;

}

for(q=0;q<G.length;q++) {

System.out.println(G[q]);

}

}

}


正在回答

4 回答

import java.util.Arrays;

public class HelloWorld{

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

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

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

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

? ? ? ? hello.showTop3(scores);? ??

? ? }

? ?

? ??

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

? ? ? ? Arrays.sort(scores);

? ? ? ? int num=0;

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

? ? ? ? ? ? if(scores[i]>=0 && scores[i]<=100){

? ? ? ? ? ? ? ? num++;

? ? ? ? ? ? ? ? if(num<=3){

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

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? }? ??

? ? }

}


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

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();

? ? ?hello.sortAndPrint(scores);

? ? ? ??

? ? ? ??

? ? }

? ??

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

? ? public void sortAndPrint(int[] xscores){

? ? ? ? Arrays.sort(xscores);//排序,但默認(rèn)是升序

? ? ? ? int len = xscores.length;

? ? ? ? int[] scores= new int[len];

? ? ? ? int count =0;//計(jì)數(shù)

? ? ? ? //把升序變?yōu)榻敌?/p>

? ? ? ? for(int i=0;i<xscores.length;i++){

? ? ? ? ? ? scores[i]=xscores[len-1-i];

? ? ? ? }

? ? ? ? xscores=scores;

? ? ? ? //輸出前三

? ? ? ? for(int i=0;i<xscores.length;i++){

? ? ? ? ? ? //驗(yàn)證數(shù)據(jù)是否有效

? ? ? ? ? ? if(xscores[i]>0&&xscores[i]<100){

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

? ? ? ? ? ? //找到即輸出,計(jì)數(shù)+1

? ? ? ? ? ? count++;

? ? ? ? ? ? //找到三個(gè),跳出循環(huán)

? ? ? ? ? ? if(count==3)

? ? ? ? ? ? break;

? ? ? ? ? ? }

? ? ? ? }

? ? }

? ??

這是我做的,可用,你可以對(duì)比一下

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

一艘小船飄啊搖啊

這里降序可以用倒序法來寫啊 直接用 for(int i=scores.length-1; i>=0 ;i--){ }//倒序 從大往小遍歷 for(int i=0; i<scores.length; i++){ }//升序 從小往大遍歷
2019-04-09 回復(fù) 有任何疑惑可以回復(fù)我~
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();?????hello.sortAndPrint(scores);????????????????????}????????//定義方法完成成績(jī)排序并輸出前三名的功能????public?void?sortAndPrint(int[]?xscores){????????Arrays.sort(xscores);//排序,但默認(rèn)是升序????????int?len?=?xscores.length;????????int[]?scores=?new?int[len];????????int?count?=0;//計(jì)數(shù)????????//把升序變?yōu)榻敌????????for(int?i=0;i<xscores.length;i++){????????????scores[i]=xscores[len-1-i];????????}????????xscores=scores;????????//輸出前三????????for(int?i=0;i<xscores.length;i++){????????????//驗(yàn)證數(shù)據(jù)是否有效????????????if(xscores[i]>0&&xscores[i]<100){????????????System.out.println(xscores[i]);????????????//找到即輸出,計(jì)數(shù)+1????????????count++;????????????//找到三個(gè),跳出循環(huán)????????????if(count==3)????????????break;????????????}????????}????}


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

太多錯(cuò)了,主函數(shù)都沒有,上面的代碼方法也沒,你調(diào)用的是其他頁面的方法?

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

舉報(bào)

0/150
提交
取消

請(qǐng)問怎么沒辦法輸出前三名,是方法哪里寫錯(cuò)了

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

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

幫助反饋 APP下載

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

公眾號(hào)

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