題目
package ch4;
import java.io.*;
public class ch4_19
{
public static void main(String args[])throws IOException
{
InputStreamReader in=new InputStreamReader(System.in);
BufferedReader buf=new BufferedReader(in);
String name1,name2,name3;
int chi1,eng1,mat1,chi2,eng2,mat2,chi3,eng3,mat3;
int sum1,sum2,sum3,chsu,ensu,masu;
double chav,enav,maav,avg1,avg2,avg3;
String strchi1,strmat1,streng1,strchi2,streng2,strmat2,strchi3,streng3,strmat3;
System.out.println("請依序輸入座號一號的姓名國文英文和數學成績");
name1=buf.readLine();
strchi1=buf.readLine();
chi1=Integer.parseInt(strchi1);
streng1=buf.readLine();
eng1=Integer.parseInt(streng1);
strmat1=buf.readLine();
mat1=Integer.parseInt(strmat1);
System.out.println("請依序輸入座號二號的姓名國文英文和數學成績");
name2=buf.readLine();
strchi2=buf.readLine();
chi2=Integer.parseInt(strchi2);
streng2=buf.readLine();
eng2=Integer.parseInt(streng2);
strmat2=buf.readLine();
mat2=Integer.parseInt(strmat2);
System.out.println("請依序輸入座號三號的姓名國文英文和數學成績");
name3=buf.readLine();
strchi3=buf.readLine();
chi3=Integer.parseInt(strchi3);
streng3=buf.readLine();
eng3=Integer.parseInt(streng3);
strmat3=buf.readLine();
mat3=Integer.parseInt(strmat3);
sum1=chi1+eng1+mat1;
avg1=(double)sum1/3;
sum2=chi2+eng2+mat2;
avg2=(double)sum2/3;
sum3=chi3+eng3+mat3;
avg3=(double)sum3/3;
System.out.println("座號一號姓名:"+name1+",國文:"+chi1+",英文"+eng1+",數學"+mat1+",總分"+sum1+",平均"+avg1);
System.out.println("座號一號姓名:"+name2+",國文:"+chi2+",英文"+eng2+",數學"+mat2+",總分"+sum2+",平均"+avg2);
System.out.println("座號一號姓名:"+name3+",國文:"+chi3+",英文"+eng3+",數學"+mat3+",總分"+sum3+",平均"+avg3);
chsu=chi1+chi2+chi3;
chav=(double)chsu/3;
ensu=eng1+eng2+eng3;
enav=(double)ensu/3;
masu=mat1+mat2+mat3;
maav=(double)masu/3;
System.out.println("各科總分,國文:"+chsu+",英文:"+ensu+",數學:"+masu);
System.out.println("各科平均,國文:"+chav+",英文:"+enav+",數學:"+maav);
}
}
輸出結果
請依序輸入座號一號的姓名國文英文和數學成績
AA
22
33
44
請依序輸入座號二號的姓名國文英文和數學成績
BB
55
66
77
請依序輸入座號三號的姓名國文英文和數學成績
CC
88
99
99
座號一號姓名:AA,國文:22,英文33,數學44,總分99,平均33.0
座號一號姓名:BB,國文:55,英文66,數學77,總分198,平均66.0
座號一號姓名:CC,國文:88,英文99,數學99,總分286,平均95.33333333333333
各科總分,國文:165,英文:198,數學:220
各科平均,國文:55.0,英文:66.0,數學:73.33333333333333
留言列表