返回列表 發帖

if...else 判斷式

利用 if...else 判斷式, 設計一程式判斷使用者是否可以考駕照了.
  1. import java.io.Console;
  2. public class ch9
  3. {
  4.     public static void main(String args[])
  5.     {
  6.          Console console=System.console();
  7.          int age;
  8.          System.out.print("請輸入你的年紀: ");
  9.          age=Integer.parseInt(console.readLine());
  10.          if(age>=18)
  11.          {
  12.               System.out.print("恭喜你可以考駕照了!");
  13.          }
  14.          else
  15.          {
  16.               System.out.print("哎呀未滿18歲, 還得等一等!");
  17.          }
  18.     }
  19. }
複製代碼

返回列表