為什么用帶參帶返回值的方法不行?
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 是什么意思?
? ? }
}
}
}
2020-02-07
調(diào)用方法時沒有寫實參
2019-11-28
你方法返回的數(shù)組,但是返回賦值給了一個整型,方法返回值改為一個int值就可以
2019-11-28
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;
? ? }?
}
重新寫了一遍 這回對了
2019-11-27
帶參方法:說明該方法在使用時要特別指定一些限制或要求,比如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)。