Discuss / Java / 练习

练习

Topic source
public class Main {
    public static void main(String[] args) {
    	int[][] scores = {
                { 82, 90, 91 },
                { 68, 72, 64 },
                { 95, 91, 89 },
                { 67, 52, 60 },
                { 79, 81, 85 },
    	};
    	double average = 0;
    	int sum =0;
    	int count = 0;

    	for(int i = 0; i < scores.length; i++) {
    		
    		for(int j = 0; j < scores[i].length; j++) {
    			System.out.print(scores[i][j]+",");
    			sum += scores[i][j];
    			count++;
    		}
    		System.out.println();
    	}
    	average = (double)sum / count;
    	System.out.println(average);//77.73333333333
    	if(Math.abs(average - 77.733333) < 0.000001) {
    		System.out.println("测试成功");
    	}
    	else {
    		System.out.println("测试失败");
    	}
	}
}


  • 1

Reply