返回列表 發帖

[牛刀小試] if...else if...else 判斷式 (二)

利用if...else if...else語法, 試做一成績分級程式.
90分~100分  優
  80分~89分  甲
  70分~79分  乙
  60分~69分  丙
    0分~59分  丁

本帖最後由 王可同 於 2020-8-18 11:31 編輯
  1. import java.io.Console;
  2. public class M
  3. {
  4.   public static void main(String args[])
  5.   {
  6.   Console c=System.console();
  7.   int x;
  8.   System.out.print("輸入成績:");
  9.   x=Integer.parseInt(c.readLine());
  10.   if(x<=100&&x>=90)
  11.   System.out.println("優");
  12.   else if(x<=89&&x>=80)
  13.   System.out.println("甲");
  14.   else if(x<=79&&x>=70)
  15.   System.out.println("乙");
  16.   else if(x<=69&&x>=60)
  17.   System.out.println("丙");
  18.   else if(x<=59&&x>=0)
  19.   System.out.println("丁");
  20.   else
  21.   System.out.println("輸入錯誤!");
  22.   }
  23. }
複製代碼

TOP

本帖最後由 劉柏瓘 於 2020-8-18 11:33 編輯
  1. import java.io.Console;
  2. public class A
  3. {
  4.    public static void main(String args[])
  5.     {
  6.           int x;
  7.           Console c=System.console();
  8.           x=Integer.parseInt(c.readLine("請輸入成績:"));

  9.            if(x>=90&&x<=100)
  10.                 System.out.println("優");
  11.            else if(x>=80&&x<=89)
  12.                 System.out.println("甲");
  13.            else if(x>=70&&x<=79)
  14.                 System.out.println("乙");
  15.            else if(x>=60&&x<=69)
  16.                 System.out.println("丙");
  17.            else if(x>=0&&x<=59)
  18.                 System.out.println("丁");
  19.            else
  20.                 System.out.println("輸入錯誤!!!!!");


  21.     }
  22. }
複製代碼

TOP

  1. import java.io.Console;
  2. public class XX
  3. {
  4.   public static void main(String args[])
  5.   {
  6.     Console c=System.console();

  7.     while (0<1)
  8.     {
  9.       float x;
  10.       System.out.println("輸入成績(0~100): ");
  11.       x=Float.parseFloat(c.readLine());
  12.       if (90<=x&&x<=100)
  13.       {
  14.         System.out.println("優");
  15.       }
  16.       else if (80<=x&&x<=89)
  17.       {
  18.         System.out.println("甲");
  19.       }
  20.       else if (70<=x&&x<=79)
  21.       {
  22.         System.out.println("乙");
  23.       }
  24.       else if (60<=x&&x<=69)
  25.       {
  26.         System.out.println("丙");
  27.       }
  28.       else if (0<=x&&x<=59)
  29.       {
  30.         System.out.println("丁");
  31.       }
  32.       else
  33.       {
  34.         System.out.println("輸入錯誤,請重新輸入");
  35.         System.out.println("********************");
  36.       }








  37.     }



  38.   }




  39. }
複製代碼

TOP

  1. //成績
  2. import java.io.Console;
  3. public class f
  4. {
  5.   public static void main(String args[])
  6.   {
  7.    int x;
  8.    Console c=System.console();
  9.    System.out.print("輸入成績:");
  10.    x=Integer.parseInt(c.readLine());

  11.    if(x>=90 && x<=100)
  12.           System.out.println("優");
  13.    else if(x>=80 && x<=89)
  14.           System.out.println("甲");
  15.    else if(x>=70 && x<=79)
  16.           System.out.println("乙");
  17.    else if(x>=60 && x<=69)
  18.           System.out.println("丙");
  19.    else if(x>=0 && x<=59)
  20.           System.out.println("丁");
  21.    else
  22.           System.out.println("輸入錯誤!");
  23.   }
  24. }
複製代碼

TOP

  1. import java.io.Console ;
  2. public class R
  3. {
  4.   public static void main(String args[])
  5.    {  int x;
  6.    Console g=System.console();
  7.    x=Integer.parseInt(g.readLine("輸入成績 ") );

  8.    if(x>=90&&x<=100)
  9.        System.out.println("優");
  10.    else if(x>=80&&x<=89)
  11.        System.out.println("甲");
  12.    else if(x>=70&&x<=79)
  13.        System.out.println("乙");
  14.    else if(x>60&&x<=69)
  15.        System.out.println("丙");
  16.    else if(x>=0&&x<=59)
  17.        System.out.println("丁");
  18.    else
  19.        System.out.println("錯誤");

  20.    }


  21. }
複製代碼

TOP

  1. import java.io.Console;
  2. public class a
  3. {
  4.      public static void main(String args[])
  5.      {
  6.            int x;
  7.            Console c=System.console();
  8.            x=Integer.parseInt(c.readLine("請輸入分數: "));
  9.            if (x<0||x>100)
  10.            System.out.println("錯誤!");
  11.            else if(x>=90)
  12.            System.out.println("優!");
  13.            else if(x>=80)
  14.            System.out.println("甲!");
  15.            else if(x>=70)
  16.            System.out.println("乙!");
  17.            else if(x>=60)
  18.            System.out.println("丙!");
  19.            else if(x<60)
  20.            System.out.println("丁!");
  21.            
  22.      }
  23. }
複製代碼

TOP

  1. import java.io.Console;
  2. public class E
  3. {
  4.     public static void main(String args[])
  5.     {
  6.          int x;
  7.          Console c=System.console();
  8.          System.out.print("輸入x: ");
  9.          x=Integer.parseInt(c.readLine());
  10.          if(x>=90 && x<=100)
  11.              System.out.println("優");
  12.          else if(x<=89 && x>=80)
  13.              System.out.println("甲");
  14.          else if(x<=79 && x>=70)
  15.              System.out.println(" 乙");
  16.          else if(x<=69 && x>=60)
  17.              System.out.println("丙");
  18.          else if(x<=59 && x>=0)
  19.              System.out.println("丁");
  20.          else
  21.              System.out.println("壞掉囉");

  22.     }
  23. }
複製代碼

TOP

  1. import java.io.Console;
  2. public class Test
  3. {
  4.   public static void main(String args[])
  5.   {
  6.     Console c=System.console();
  7.     int x;
  8.     x=Integer.parseInt(c.readLine("請輸入x"));

  9.     if(100>=x&&x>=90)
  10.         System.out.println("優");
  11.     else if(90>x&&x>=80)
  12.         System.out.println("甲");
  13.     else if(80>x&&x>=70)
  14.         System.out.println("乙");
  15.     else if(70>x&&x>=60)
  16.         System.out.println("丙");
  17.     else if(60>x&&x>=0)
  18.         System.out.println("丁");
  19.   }

  20. }
複製代碼

TOP

返回列表