請(qǐng)幫我看下我這段代碼能運(yùn)行出來(lái)么,謝謝
import java.util.Arrays;
public class HelloWorld {
public static void main(String[] args) {
HelloWord t=new HelloWord;
int[] e=a.ppp(1,2,-1,-5);
System.out.print(e);
}
public void ppp(int[] scores) {
System.out.print("考試成績(jī)前三名:");
Arrays.sort(scores);
for(int i=0;i<=3;i++){
if(0<=scores[i]<=100){
System.out.print(scores[i]);
}else{
System.out.print(scores[i]"該成績(jī)不符合要求");
}
}
}
}
2015-07-22
不能那樣寫(xiě)的!數(shù)組賦值需要循環(huán)語(yǔ)句或者直接初始化。你是在調(diào)用ppp方法,但ppp方法卻不是給數(shù)組賦值的方法,編譯無(wú)法通過(guò)。
2015-07-22
ppp()方法的參數(shù)是整型數(shù)組,你這個(gè)1,2,-1,-5對(duì)應(yīng)的是各個(gè)數(shù)組元素,和ppp方法不能匹配的
2015-07-22
int[] e=t.ppp(1,2,-1,-5);//我不清楚這塊可不可以這么寫(xiě),望指點(diǎn)
改成這樣int[] e = t.ppp({1,2,-1,-5});
2015-07-22
import java.util.Arrays;
public class HelloWorld {
public static void main(String[] args) {
HelloWord t=new HelloWord;
int[] e=t.ppp(1,2,-1,-5);//我不清楚這塊可不可以這么寫(xiě),望指點(diǎn)
System.out.print("考試成績(jī)前三名:");
}
public void ppp(int[] scores) {
Arrays.sort(scores);
for(int i=scores.length-1;i>=0;i--){
if(0<=scores[i]&&scores[i]<=100){
System.out.print(scores[i]);
}else{
System.out.print(scores[i]"該成績(jī)不符合要求");
}
}
}
}