返回列表 發帖

if...else if...else 判斷式 (一)

運用 if...else if...else 判斷式, 比較 x 與 y 的大小關係.



  1. import java.io.Console;
  2. public class Ch09
  3. {
  4.     public static void main(String args[])
  5.     {
  6.          Console c=System.console();
  7.          int x,y;
  8.          System.out.print("輸入x: ");
  9.          x=Integer.parseInt(c.readLine());
  10.          System.out.print("輸入y: ");
  11.          y=Integer.parseInt(c.readLine());
  12.          if(x>y)
  13.              System.out.println("x>y");
  14.          else if(x<y)
  15.              System.out.println("x<y");
  16.          else
  17.              System.out.println("x=y");
  18.     }
  19. }
複製代碼

返回列表