請用二維陣列
計算每人總分和平均
每人不及格數
各科平均
請加入可輸入成績功能和各科不及格數(可選)
package ch7;
import java.io.*;
public class ch7_13_1
{
public static void main(String awgs[])throws IOException
{
InputStreamReader in=new InputStreamReader(System.in);
BufferedReader buf=new BufferedReader(in);
int num[][]= {
{0,0,0,0,0,0,0,0},
{1,50,60,70,0,0,0,0},
{2,30,40,50,0,0,0,0},
{3,70,80,90,0,0,0,0},
{4,66,77,88,0,0,0,0},
{5,22,33,66,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0}};
System.out.println(num[1][3]);
int a,b,sum=0,avg=0,cunt,c=0;
final int s=5;
String snum;
for(a=1;a<=5;a++)
{
for(b=1;b<=3;b++)
{
snum=buf.readLine();
num[a][b]=Integer.parseInt(snum);
}
}
for(b=1;b<=3;b++)
{
c=0;
for(a=1;a<=5;a++)
{
if(num[a][b]<60)
{
c++;
}
}
num[7][b]=c;
}
for(a=1;a<=6;a++)
{
sum=0;
avg=0;
cunt=0;
for(b=1;b<=3;b++)
{
sum=sum+num[a][b];
avg=avg+num[a][b];
if(num[a][b]<60)
{
cunt=cunt+1;
}
}
num[a][4]=sum;
num[a][5]=avg/3;
num[a][6]=cunt;
}
for(b=1;b<=4;b++)
{
avg=0;
for(a=1;a<=5;a++)
{
avg=avg+num[a][b];
}
avg=avg/s;
num[a][b]=avg;
}
for (a=1;a<=6;a++)
{
for(b=1;b<=6;b++)
{
}
}
System.out.println("座號國文英文數學總分平均不及格數");
for(a=1;a<=5;a++)
{
for(b=0;b<=6;b++)
{
System.out.print(" "+num[a][b]+" ");
}
System.out.println();
}
for(a=6;a<=6;a++)
{
for(b=0;b<=6;b++)
{
System.out.print(" ");
System.out.print(num[a][b]+" ");
if(num[a][b+1]<10)
{
System.out.print(" ");
}
}
System.out.println();
}
for(a=7;a<=7;a++)
{
for(b=0;b<=6;b++)
{
System.out.print(" ");
System.out.print(num[a][b]+" ");
if(num[a][b+1]<10)
{
System.out.print(" ");
}
}
System.out.println();
}
}
}
=====
70
50
60
70
30
40
50
70
80
90
66
77
88
22
33
66
座號國文英文數學總分平均不及格數
1 50 60 70 180 60 1
2 30 40 50 120 40 3
3 70 80 90 240 80 0
4 66 77 88 231 77 0
5 22 33 66 121 40 2
0 47 58 72 178 0 3
0 3 2 1 0 0 0
留言列表