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

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

為什么用帶參帶返回值的方法不行?

import java.util.Arrays;

public class HelloScore {

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

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

? ? ? HelloScore score = new HelloScore();

? ? ? int sortthenum = score.sortScore();

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

? ? }

public int sortScore(int[] scores){

? ? Arrays.sort(scores);

? ? int j = 0;

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

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

? ? ? ? continue;

? ? }else{

? ? ? ? j++;?

? ? ? ? if (j > 3){

? ? ? ? ? ?break;

? ? } ??

? ? return int[] scores;//這一句總是報錯說: ? '.class' expected 是什么意思?

? ? }

}

}

}


正在回答

4 回答

調(diào)用方法時沒有寫實參

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

你方法返回的數(shù)組,但是返回賦值給了一個整型,方法返回值改為一個int值就可以

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

import java.util.Arrays;


public class HelloScore {

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

? ? ? double[] scores = { 8.9, -2.3, 6.4, 9.1, 11.9, 5.2, 7.3};?

? ? ? HelloScore score = new HelloScore();

? ? ? double[] sortthenum = score.sortScore(scores);

? ? ? System.out.println(Arrays.toString(sortthenum));

? ? }


? ? public double[] sortScore(double[] scores){

? ? ? ? Arrays.sort(scores);

? ? ? ? int j = 0;

? ? ? ? double[] validscore = new double[3];

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

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

? ? ? ? ? ? ? ? continue;

? ? ? ? ? ? }else{

? ? ? ? ? ? validscore[j] = scores[i];

? ? ? ? ? ? j++;?

? ? ? ? ? ? if (j > 2){

?? ? ? ? ? ? ? break;

? ? ? ? ? ? }? ?

? ? ? ? }

? ? ? ? }

? ? ? ? return validscore;

? ? }?

}

重新寫了一遍 這回對了

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

帶參方法:說明該方法在使用時要特別指定一些限制或要求,比如add(int x,iny),就是計算x+y的值,x,y在術(shù)語上稱為形參,所以你使用時,要告訴他x,y都是什么,而這一做法在術(shù)語上稱為傳參,比如add(5,6),而具體5,6,就是你具體傳入的值,在術(shù)語上稱為實參。
int add(int x,iny),前面的int就是說明這個方法有返回值,類型是int的。說明這個方法要將計算結(jié)果通過返回一個int值來告訴你,你在使用的時候,需要接收這個返回值,比如int a=add(5,6)。

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

舉報

0/150
提交
取消

為什么用帶參帶返回值的方法不行?

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

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

幫助反饋 APP下載

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

公眾號

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