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

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

用帶參帶返回值不能完成這個(gè)嗎?

import java.util.Arrays;

public class HelloWorld {

? ? //完成 main 方法

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

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

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

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

? ? ? ? int b = hello.count(scores);

? ? ? ? System.out.println(b);

? ? ? ??

? ? }

? ??

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

public int count(int scores[]){

? ? Arrays.sort(scores);

? ? int num = 0;

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

? ? ? ? int a = 0;

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

? ? ? ? ? ? continue;

? ? ? ? }

? ? ? ? a = scores[i];

? ? ? ? num++;

? ? ? ? if(num > 3){

? ? ? ? ? ? break;

? ? ? ? }

? ? ? ? return a;

? ? }

}

}


請(qǐng)問(wèn)這樣錯(cuò)在哪里呢


正在回答

2 回答

用帶參帶返回值可以完成:

package test4;

import java.util.Arrays;

public class Test45 {

? ?//完成 main 方法

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

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

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

? ? ? ?Test45 hello = new Test45(); ? ?

? ? ? ?int[] b = hello.count(scores);//將返回值賦給數(shù)組b

? ? ? ?System.out.println(Arrays.toString(b));//用Arrays.toString方法輸出數(shù)組b的內(nèi)容

? ?}

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

public int[] count(int[] scores){//返回值類型應(yīng)該為數(shù)組int[]

? ? ? ? int[] a = new int[3];//定義數(shù)組a的長(zhǎng)度

? ?Arrays.sort(scores);//排序

? ?int num = 0;

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

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

? ? ? ? ? ?continue;

? ? ? ?}


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

? ? ? ? ? ?break;

? ? ? ?}else{//數(shù)組a賦值前三名的成績(jī)

? ? ? ? a[num] = scores[i];

? ? ? ? }

? ? ? ? ? ? num++;

? ?}

? ? ? ? return a;//返回?cái)?shù)組a的內(nèi)容

}

}

改動(dòng)的地方都有注釋,可以看著理解一下

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

你的數(shù)組聲明就有問(wèn)題 ?應(yīng)該是 int[] scores??= {89, -23, 64, 91, 119, 52, 73};吧 ?還有就是傳參 ?也應(yīng)該是public int count(int[] scores)

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

舉報(bào)

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

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

進(jìn)入課程

用帶參帶返回值不能完成這個(gè)嗎?

我要回答 關(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)