這樣提交會(huì)提示系統(tǒng)忙,是運(yùn)行不出來么
下面for循環(huán)哪里while改成if會(huì)輸出5個(gè)成績,但是用while提交上去會(huì)提示系統(tǒng)忙,,
import java.util.Arrays;
public class HelloWorld {
? ??
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ? ? ? HelloWorld hello = new HelloWorld();?
? ? ? ? int[] scores={89,-23,64,91,119,52,73};
? ? ? ? System.out.println("考試成績的前三名為:");
? ? ? ? hello.up(scores);
? ? ? ??
? ? ? ??
? ? ? ??
? ? }
? ??
? ? //定義方法完成成績排序并輸出前三名的功能
? ??
? ? public void up(int[] scores){
? ? ? ? Arrays.sort(scores);
? ? ? ??
? ? ? ??
? ? ? ? for(int i=scores.length-1,j=0;i>=0||j<3;i--){
? ? ? ? ? ? if(scores[i]>=0){
? ? ? ? ? ? ? ? while(scores[i]<=100){
? ? ? ? ? ? ? ? ? ?System.out.println(scores[i]);
? ? ? ? ? ? ? ? ? ?j++;
? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? ? ??
? ? ? ??
? ? ? ? }
2017-08-26
方法處應(yīng)該這樣改:
public void up(int[] scores){
? ? ? ? Arrays.sort(scores);? ? ? ?
? ? ? ? for(int i=scores.length-1,j=0;i>=0&&j<3;i--){ ? ? //這里應(yīng)該用&&,兩個(gè)條件都必須符合
? ? ? ? ? ? if(scores[i]>=0&&scores[i]<=100){? ? ? ? ? ?//判斷應(yīng)該按正規(guī)的來,你這個(gè)if ?while不好也不正規(guī),感? ? ????????????????????????????????????????????????????????????????????????? ??
? ? ? ? ? ? ? ? ? ?System.out.println(scores[i]); ? ? ? ? ? ?//覺也不正確,就按if else來
? ? ? ? ? ? ? ? ? ?j++;}
????????????else
????????????????????continue;? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //這個(gè)循環(huán)里面需要用到continue
? ? ? ? ? ? ?}
?}? ? ? ?