成績計算程式

Home Home
引用 | 編輯 chpo
2009-03-19 23:36
樓主
推文 x0
怎樣寫出 讓使用者輸入3科成績 程式就可以算出 平均數(要整數)呢?

算出來以後 90~100 對應出來顯 ..

訪客只能看到部份內容,免費 加入會員



獻花 x0
引用 | 編輯 totsi
2009-03-20 09:00
1樓
  
http://www.dk101.com/Discuz/viewthread.php?tid=74231
這邊有你要的答案,而且題目是一模一樣的... 表情

獻花 x0
引用 | 編輯 chpo
2009-03-20 11:35
2樓
  
但是他是用c++呢 這在JAVA可用嗎?

獻花 x0
引用 | 編輯 rchockxm
2009-03-20 14:40
3樓
  
只要改一下語法就好了

大部分架構都差不多的 表情

java 取得輸入可以用下面這個或是其他的方法
Scanner getinput = new Scanner(System.in);
System.out.print( "請輸入成績一" );
input1 = getinput.nextInt();
System.out.print( "請輸入成績二" );
input2 = getinput.nextInt();
System.out.print( "請輸入成績三" );
input3 = getinput.nextInt();
getinput.close();

再做運算和 Switch 判斷值

最後在輸出就好了...

其他就不打了

totsi 大貼的連結都差不多了... 表情

推薦這個網站 http://caterpillar.onlyfun.net/Gossip/JavaGossip-V1/JavaGossip.htm

獻花 x0
引用 | 編輯 jim28791
2009-04-23 23:57
4樓
  
這應該是你要的吧!?
既然無法使用if的範圍方法
那就直接除以10~
就也可以達到與if相同的範圍方法!!

複製程式
import java.io.*;
class bn
{
  public static void main(String args[]) throws IOException
  {
      BufferedReader buf;
      String str,str2;
      int avg=0;
      buf = new BufferedReader(new InputStreamReader(System.in));
      for(int i=0;i<3;i++)
      {
      System.out.println("請輸入第"+(i+1)+"科成績:");
      str= buf.readLine();
      avg+=Integer.parseInt(str);
      }
      avg/=3;
      switch(avg/10)
      {
             case 10:
             case 9:
             str2="A";
             break;
             case 8:
             str2="B";
             break;
             case 7:
             str2="C";
             break;
             case 6:
             str2="D";
             break;
             default:
             str2="E";
      }
      System.out.println("平均分數:"+avg+"\n得到的分數是:"+str2);
  }
}

為什麼一定要限制在50行內!?
如果我全部縮起來~~
也可以達到1行完成呀 !!

你的意思應該是case不能從100一直case到0吧!!

獻花 x0