1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class CH01001 { public static void main(String args[]) throws IOException { BufferedReader buf = new BufferedReader( new InputStreamReader(System.in)); int num = 0 ; do { System.out.print( "請輸入一個大於10的數字:" ); num = Integer.parseInt(buf.readLine()); } while (num < 10 ); System.out.println( "你輸入的數字是 " + num); } } |
「do...while」與「while」相似,不同的是「do...while」至少會執行1次「while」若條件不符合連1次都不會執行。
沒有留言:
張貼留言