若有3个班级各4名学员参赛,如何计算每个班级参赛学员的平均分?
int total=0;
int[] calss=new int[3];
for (int i=0;i<3;i++)
{
Scanner scanner=new Scanner(System.in);
System.out.println("请输入第"+(i+1)+"的班级成绩");
// calss[i]=scanner.nextInt();
int[] score=new int[4];
for (int z=0;z<4;z++)
{
Scanner scanner1=new Scanner(System.in);
System.out.println("请输入第"+(z+1) +"学员的考试成绩");
score[z]=scanner.nextInt();
total=total+score[z];
}
System.out.println(total/4);
}
如何用*打印矩形图案?
for (int i=0;i<5;i++)
{
for (int z=0;z<5;z++)
{
System.out.print("*\t");
}
System.out.println("");
}
打印倒直角三角形
for (int m=5;m>0;m--)
{
for (int i=0;i<m;i++)
{
System.out.print("*\t");
}
System.out.println(" ");
}
打印九九乘法表
for (int i=0;i<9;i++)
{
for (int z=0;z<1+i;z++)
{
System.out.print((i+1)+"*"+(z+1)+"="+(i+1)*(z+1)+"\t");
}
System.out.println(" ");
网友评论