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

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定

憋著一泡屎寫出來的,花了一個小時,把我痛苦的呀!參考代碼

import java.util.Arrays;

public class HelloWorld {

? ??

? ? //完成 main 方法

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

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

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

? ? ? ? hello.scoreArray(arrays);

? ? ? ??

? ? ? ??

? ? ? ??

? ? }

? ??

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

? ??

? ? public int[] scoreArray(int[] arrays){

? ? ? ??

? ? ? ? Arrays.sort(arrays);

? ? ? ? int numb = 1;

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

? ? ? ? ? ? if(arrays[i]<0){

? ? ? ? ? ? ? ? continue;

? ? ? ? ? ? }

? ? ? ? ? ? if(arrays[i]>100){

? ? ? ? ? ? ? ? continue;

? ? ? ? ? ? }

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

? ? ? ? ? ? numb++;

? ? ? ? ? ? if(numb>3){

? ? ? ? ? ? ? ? break;

? ? ? ? ? ? }

? ? ? ? }

? ? ? ? return arrays;

? ? }


}


正在回答

5 回答

可以用樓上的void 不用返回值

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

這樣的話main里邊調(diào)用的結(jié)果為數(shù)組,hello.scoreArray(arrays)這個為數(shù)組,還需要輸出數(shù)組或者逐個賦值

例如:

int num1=hello.scoreArray(arrays)[0];

int num2=hello.scoreArray(arrays)[1];

int num3=hello.scoreArray(arrays)[2];

然后輸出這三個變量

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

scoreArray方法里再創(chuàng)建一個數(shù)組,把需要輸出的數(shù)值賦值給新的數(shù)組,然后返回值為新的數(shù)組

numb初始值改為0

例如:

?public int[] scoreArray(int[] arrays){

? ? ? ??

? ? ? ? Arrays.sort(arrays);

? ? ? ??//int numb = 1;

????????int numb=0;? ? ? //初始值為0,在0的基礎(chǔ)上做3次自加加運算,最后結(jié)果為3

????????int [] arr=new int[3];? ? ?//新的數(shù)組,因為要輸出前3名,所以長度為3

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

? ? ? ? ? ? if(arrays[i]<0){

? ? ? ? ? ? ? ? continue;

? ? ? ? ? ? }

? ? ? ? ? ? if(arrays[i]>100){

? ? ? ? ? ? ? ? continue;

? ? ? ? ? ? }

????????????//可以合為一句

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

????????????????continue;

?????????????}

? ? ? ? ? ? System.out.println(arrays[i]);??//這行可以不要

? ? ? ? ? ? numb++;

? ? ? ? ? ? if(numb>3){

? ? ? ? ? ? ? ? break;

? ? ? ? ? ? }

????????? ?arr[numb-1]=arrays[i];? //這里開始逐個賦值,此循環(huán)中numb的值為1、2、3,

? ? ? ? }

? ? ? ? return arrays;

????????return arr;? ?//這里返回值為數(shù)組arr

? ? }


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

不用返回了


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

import java.util.Arrays;

//導(dǎo)入功能包;

public class HelloWorld?

{

? ??

? ? //完成 main 方法

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

? ? {

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

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

? ? hello.function(scores); ? ?

? ? }

? ??

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

? ??

? ? public void function(int[] scores)

? ? {

? ? ? ? int count=0;

? ? ? ? Arrays.sort(scores);

? ? ? ?// int marks[3] ;

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

? ? ? ? {

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

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

? ? ? ? ? ? count++;

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

? ? ? ? ? ??

? ? ? ? }

? ? ? ??

? ? }

}


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

舉報

0/150
提交
取消

憋著一泡屎寫出來的,花了一個小時,把我痛苦的呀!參考代碼

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

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

幫助反饋 APP下載

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

公眾號

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