返回列表 發帖

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

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





  二擇一
  if( )
  {

  }
  else
  {

  }

  多擇一
  if( )
  {

  }
  else if( )
  {

  }
  else if( )
  {

  }
  else
  {

  }

  多擇多 / 多擇無
  if( )
  {
         
  }
  if( )
  {

  }
  if( )
  {

  }
  if( )
  {
         
  }


本帖隱藏的內容需要回復才可以瀏覽

  1. import java.io.Console;
  2. public class Ch10
  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. }
複製代碼

TOP

  1. import java.io.Console;
  2. public class Ch10
  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. }
複製代碼

TOP

  1. import java.io.Console;
  2. public class Ch07
  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. }
複製代碼

TOP

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

TOP

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

TOP

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

TOP

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

  17. }
複製代碼

TOP

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

TOP

  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.         x=Integer.parseInt(c.readLine("請輸入x: "));
  9.         y=Integer.parseInt(c.readLine("請輸入y: "));
  10.         if(x>y)
  11.             System.out.println("x大於y");
  12.         else if(x<y)
  13.             System.out.println("x小於y");
  14.         else
  15.             System.out.println("兩數相等");

  16.     }
  17. }
複製代碼

TOP

  1. import java.io.Console;
  2. public class Ch10
  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. }
複製代碼

TOP

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

TOP

返回列表