大神求指教 為什么輸不出成績
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("考試成績的前三名:");
? ? ? HelloWorld hello = new HelloWorld();
? ? ? hello.stuScore(scores);
? ? ? ??
? ? ? ??
? ? ? ??
? ? }
? ??
? ? //定義方法完成成績排序并輸出前三名的功能
? ? public void stuScore(int[] scores){
? ? ? ? Arrays.sort(scores);
? ? ? ? int count = 0;
? ? ? ? for(int i=scores.length-1;i>=0;i--){
? ? ? ? ? ? if(scores[i]>0 || scores[i]<100){
? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? }
? ? ? ? ? ? count++;
? ? ? ? ? ? if(count>3){
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? ? ? System.out.println(scores[i]);
? ? ? ? ? ??
2015-11-30
?if(scores[i]>0 || scores[i]<100){
? ? ? ? ? ?? count++;
? ? ? ? ? ? if(count=>3){
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? ? ? System.out.println(scores[i]);
? ? ? ? ? ? }
2015-11-10
if(scores[i]>0 || scores[i]<100){
? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? }
2015-11-06
我猜你沒點運行
2015-11-06
不對,你的for循環中,應該每次循環都會走continue;?
continue是中斷循環的一種方式,當執行了continue,則當前循環結束,continue后面的代碼不再執行,而是進入下一次循環,所以你的System.out.println(scores[i]);應該是從未被執行
2015-11-06
?if(scores[i]>0 || scores[i]<100){
? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? }
這里邏輯有問題,除了那個-23,你其他的數字都會因為上面的邏輯判斷進入下一循環