package com.jdlh.common.utils;
import java.util.Scanner;
public class Demo {
private static int[][] arr = new int[2][];
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
arr[0] = new int[3];
arr[1] = new int[5];
for (int i = 0; i < arr.length; i++) {
System.out.println("输入第"+(i+1)+"小组成绩:");
for (int j = 0; j < arr[i].length; j++) {
arr[i][j] = scanner.nextInt();
}
}
printResult(arr);
Demo demo = new Demo();
System.out.println("*****************");
double groupOne = demo.calGroup(arr[0]);
System.out.println("第一小组平均成绩:" + groupOne);
double groupTwo = demo.calGroup(arr[1]);
System.out.println("第二小组平均成绩:" + groupTwo);
}
public double calGroup(int rst[]){
if (rst.length == 0){
return 0.0;
}
double sum = 0.0;
for (int i = 0; i < rst.length; i++) {
sum += rst[i];
}
double res = sum/(double) rst.length;
return (double) Math.round(res * 100) / 100;
}
private static void printResult(int rst[][]){
System.out.println("*******************");
System.out.println("输出各小组成绩:");
for (int i = 0; i < rst.length; i++) {
System.out.println("第"+(i+1)+"小组:");
for (int j = 0; j < rst[i].length; j++) {
System.out.print(rst[i][j]+"\t");
}
System.out.println();
}
}
}