大神求指教 為什么輸不出成績(jī)
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("考試成績(jī)的前三名:");
? ? ? HelloWorld hello = new HelloWorld();
? ? ? hello.stuScore(scores);
? ? ? ??
? ? ? ??
? ? ? ??
? ? }
? ??
? ? //定義方法完成成績(jī)排序并輸出前三名的功能
? ? 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
我猜你沒(méi)點(diǎn)運(yùn)行
2015-11-06
不對(duì),你的for循環(huán)中,應(yīng)該每次循環(huán)都會(huì)走continue;?
continue是中斷循環(huán)的一種方式,當(dāng)執(zhí)行了continue,則當(dāng)前循環(huán)結(jié)束,continue后面的代碼不再執(zhí)行,而是進(jìn)入下一次循環(huán),所以你的System.out.println(scores[i]);應(yīng)該是從未被執(zhí)行
2015-11-06
?if(scores[i]>0 || scores[i]<100){
? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? }
這里邏輯有問(wèn)題,除了那個(gè)-23,你其他的數(shù)字都會(huì)因?yàn)樯厦娴倪壿嬇袛噙M(jìn)入下一循環(huán)