剛開始學java,照著書敲了幾行代碼,代碼貼在下面
package ch3.loopControl;import javax.swing.JOptionPane;public class ConditionLoopTest { /**
 * @param args
 */
public static void main(String[] args) { int n = 5;
int k = 1;
while (n > 0) { for (; k < 10; k++) {// 內層循環無需標記 System.out.print("* "); if (k > n) { System.out.println("\rk = " + k + " n = " + n
+ "\n--- in for loop--- the loop will be continue");
continue;
// System.out.println("\n------ after the statement
// \"continue\"");注意!!這句寫在這里是錯誤的,unreachable code
}
}
}
//----------------------------------------------------
int sum = 0;
String input = "";
for (int count = 0; count < 5; count++) {

input = JOptionPane.showInputDialog("Enter a number:");
if (input == null) {
System.out
.println("You have undo the change or do nothing.....");
System.exit(0);
}
int w = Integer.parseInt(input);
if (w < 0) {
System.out
.println("the number you input is a negative!! it will be continue.....");
continue;
}
System.out.println("the result is " + (sum += w));
System.exit(0);
}
}
}
在“//----------------------------------------------------”上面和下面的程序可以單獨運行,可是如果兩者一起,就只執行上面的了,請教老師們,這是啥問題呢?
謝謝!!!