請問大神我的代碼哪里錯啦
public class HelloWord {
import java.util.Arrays;
? ?//完成 main 方法
? ?public static void main(String[] args) {
? ?int[] scores=new int[]{89,-23,64,91,119,52,73};
? ? ? ?int count=0;
? ? ? ?HelloWord gen=new HelloWord();
? ? ? ?System.out.println("考試成績的前三名是:");
? ? ? ?gen.oo(scores);? ??
? ?}
? ?
? ?//定義方法完成成績排序并輸出前三名的功能
? ?
? ?public void oo(int[] scores){
? ? ? ?Arrays.sort(scores);
? ? ? ?for(int i=scores.length;i>=0;i--){
? ? ? ? ? if(scores>0&&scores<100) {
? ? ? ? ? ?count++;
? ? ? ? ? }
? ? ? ? else if(count=3){? ? ? ?
? ? ? ? ? ?System.out.println(Arrays.toString(scores));? ? }
? ? ? ? ? else{continue;}
? ? ? ? ??
? ? ? ? ? ?? ? ? ? ?
? ? ? ?}
? ?}
? ?
? ?
? ?
? ?
? ?
? ?
? ?
? ?
}
2018-06-14
import java.util.Arrays;
public class hello{
? ?//完成 main 方法
? ?public static void main(String[] args) {
? ?int[] scores=new int[]{89,-23,64,91,119,52,73};
? ? ? ?hello gen=new hello();
? ? ? ?System.out.println("考試成績的前三名是:");
? ? ? ?gen.oo(scores); ? ?
? ?}
? ?
? ?//定義方法完成成績排序并輸出前三名的功能
? ?
? ?public void oo(int[] scores){
? int count=0;
? ? ? ?Arrays.sort(scores);
? ? ? ?for(int i=scores.length-1;i>=0;i--)
? ? ? ?{
? ? ? ? ? if(scores[i]<0||scores[i]>100)?
? ? ? ? ? {
? ? ? ? ?continue;
? ? ? ? ? }
? ? ? ? ? count++;
? ? ? ?if(count<=3)
? ? ? ? { ? ? ??
? ? ? ? ? ?System.out.println(scores[i]); ?
? ? ? ? } ? ? ? ? ??
? ? ? ?}
? ?}
2018-06-12
首先?int?count=0?要在方法內(nèi)部定義。
? 根據(jù)數(shù)組的語法,數(shù)組最后一位是它的長度-1,這里是for(int i=scores.length-1;i>=0;i--)
?count ++;? 條件應(yīng)該在?下面if判斷里
? if(scores>0&&scores<100)?這里語法錯誤,? scores?是數(shù)組,而你for循環(huán)的是scores?里的每個元素?所以應(yīng)該是scores[i].
這里輸出的應(yīng)該是? System.out.println(scores[i])?而且?應(yīng)該在第一個 if?判斷內(nèi)
第二if?不需要else ,而且判斷條件應(yīng)該是 ==,而不是= 。