為什么運(yùn)行不了?
public class HelloWorld {
? ??
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ? ? ? int[] scores={89,-23,64,91,119,52,73};
? ? ? ? System.out.println("考試前三名成績?yōu)椋?)
? ? ? ? HelloWorld hello=new HelloWorld();
? ? ? ? hello.aa3(scores);
? ? ? ? public void aa3(int[] scores){
? ? ? ? ? ? Arrays.sort(scores);
? ? ? ? ? ? for(int i=scores.length;i>=0;i--){
? ? ? ? ? ? ? ? int counts=0;
? ? ? ? ? ? ? ? if(scores[i]<0||scores[i]>100){
? ? ? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? counts++;
? ? ? ? ? ? ? ? if(counts>3){
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? System.out.println(scores[i]);
? ? ? ? ? ? }
? ? ? ? }
? ? ? ??
? ? ? ??
? ? }
? ??
2017-01-25
import java.util.Arrays;
public class HelloWorld {
? ??
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ? ? ? int[] scores={89,-23,64,91,119,52,73};
? ? ? ? System.out.println("考試前三名成績?yōu)椋?);//////此處你忘記了分號(hào);
? ? ? ? HelloWorld hello=new HelloWorld();
? ? ? ? hello.aa3(scores);///此處應(yīng)該少了分號(hào)
? ? }
? ? ? ? public void aa3(int[] scores){
? ? ? ? ? ? Arrays.sort(scores);
? ? ? ? ? ? for(int i=scores.length-1;i>=0;i--){//此處數(shù)組長度和下標(biāo)記得對(duì)應(yīng),別忘了length-1
? ? ? ? ? ? ? ? int counts=0;
? ? ? ? ? ? ? ? if(scores[i]<0||scores[i]>100){
? ? ? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? counts++;
? ? ? ? ? ? ? ? if(counts>3){
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? System.out.println(scores[i]);
? ? ? ? ? ? }
? ? ? ? }//其他一切OK,over
? ? }