請幫我看下我這段代碼能運行出來么,謝謝
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("考試成績前三名:");
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]"該成績不符合要求");
}
}
}
}
2015-07-22
不能那樣寫的!數組賦值需要循環語句或者直接初始化。你是在調用ppp方法,但ppp方法卻不是給數組賦值的方法,編譯無法通過。
2015-07-22
ppp()方法的參數是整型數組,你這個1,2,-1,-5對應的是各個數組元素,和ppp方法不能匹配的
2015-07-22
int[] e=t.ppp(1,2,-1,-5);//我不清楚這塊可不可以這么寫,望指點
改成這樣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);//我不清楚這塊可不可以這么寫,望指點
System.out.print("考試成績前三名:");
}
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]"該成績不符合要求");
}
}
}
}