Board logo

標題: if... else if... else 判斷式 [打印本頁]

作者: tonyh    時間: 2012-10-5 20:48     標題: if... else if... else 判斷式

  1. import java.lang.*;
  2. import java.io.Console;
  3. public class ch08
  4. {
  5.    public static void main(String args[])
  6.    {
  7.         Console console=System.console();
  8.         int score;
  9.         System.out.print("請輸入你的成績: ");
  10.         score=Integer.parseInt(console.readLine());
  11.         if(score==100)
  12.         {
  13.             System.out.println("哇滿分!太神了!");
  14.         }else if(score<100 && score>=60)    // && and 的意思
  15.         {
  16.             System.out.println("恭喜你及格了!");
  17.         
  18.         }else if(score>0 && score<60)
  19.         {
  20.              System.out.println("不及格!下次再努力!");
  21.         }else if(score==0)
  22.         {
  23.              System.out.println("鴉蛋!打屁屁");
  24.         }
  25.         else
  26.         {
  27.             System.out.println("輸入錯誤!");
  28.         }
  29.    }
  30. }
複製代碼

作者: 許銘欽    時間: 2012-10-5 20:53

  1. import java.io.Console; //引入java.io類別
  2. public class ch0708 //類別
  3. {
  4. public static void main(String args[]) //方法
  5. {
  6.    Console console = System.console();
  7.    float y;
  8.    System.out.print("請輸入你的成績:");
  9.    y = Float.parseFloat(console.readLine());
  10.    
  11.    if(y==100){

  12.         System.out.println("100,great!!");

  13.    }else if(y>=60 && y>0)
  14.    {

  15.         System.out.println("恭喜你及格了");

  16.    }else if(y<=60 && y>0)
  17.    {

  18.         System.out.println("不及格,下次加油");

  19.    }else if(y==0)
  20.    {

  21.         System.out.println("葡萄!!");

  22.    }else
  23.    {

  24.         System.out.println("輸入錯誤!!");
  25.    }

  26. }

  27. }
複製代碼

作者: 晏有聰    時間: 2012-10-5 20:54

  1. import java.io.Console;
  2. public class ch08
  3. {
  4.    public static void main (String showdemo[])
  5.    {
  6.     Console console=System.console();
  7.     int score;
  8.     System.out.print("Please input your score =");
  9.     score=Integer.parseInt(console.readLine());

  10.     if (score ==100)
  11.     {
  12.       System.out.println("有作弊嗎?");
  13.     }
  14.     else if(score >=60 && score <100)
  15.     {
  16.       System.out.println("恭喜及格了!!");
  17.     }
  18.     else if (score <60 && score >0)
  19.     {
  20.       System.out.println("成績不及格!!");
  21.     }
  22.     else if (score ==0)
  23.     {
  24.       System.out.println("鴨蛋一個!!!");
  25.     }
  26.       else
  27.     {
  28.       System.out.println("輸入錯誤,你是來亂的嗎?");
  29.     }
  30.    }
  31. }
複製代碼

作者: 孫家祥    時間: 2012-10-5 20:55

回復 1# tonyh
  1. import java.io.Console;
  2. public class ch08
  3. {
  4.   public static void main(String args[])
  5.   {
  6.     Console keyin=System.console();
  7.     int int1;
  8.     Float ft2;
  9.     System.out.print("請你的成績:");
  10.     int1=Integer.parseInt(keyin.readLine());
  11.     if (int1==100)
  12.     {
  13.     System.out.print("恭喜您當老師了!");
  14.     }else if(int1<100 && int1>60)
  15.     {
  16.     System.out.print("恭喜您及格了!");
  17.     }
  18.      else if(int1>0 && int1<=60)
  19.     {
  20.     System.out.print("恭喜您重修了!");
  21.     }
  22.     else if(int1==0)
  23.     {
  24.     System.out.print("恭喜您回家了!");
  25.     }
  26.     else
  27.     {
  28.     System.out.print("恭喜您亂打了!");
  29.     }
  30.   }
  31. }
複製代碼

作者: 劉永記    時間: 2012-10-5 21:02

  1. import java.lang.*;       //類別庫,常用,自動載入,可忽略
  2. import java.io.Console;  // 抓使用者key 鍵盤時會用到
  3. public class ch08//類別
  4. {
  5.   public static void main (String arg[]) //方法
  6.   {
  7.     Console cs=System.console();  //宣告cs
  8.     int score;
  9.     System.out.print("請輸入你的分數 :");
  10.     score=Integer.parseInt(cs.readLine());
  11.     if (score==100)
  12.     {
  13.       System.out.print("哇 您真是太厲害了 滿分耶!");

  14.     }else if (score<100 && score>=60 )
  15.     {
  16.       System.out.print("及格了唷!");
  17.     }else if (score>0 && score <60)
  18.     {
  19.       System.out.print("下次再加油 好嗎?");
  20.     }else if (score==0)
  21.     {
  22.       System.out.print("零分...");
  23.     }else
  24.      {
  25.       System.out.print("嘿! 不要亂輸入唷");
  26.      }
  27.   }
  28. }
複製代碼





歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/) Powered by Discuz! 7.2