Created
June 17, 2016 12:02
-
-
Save Yurlov/b069f420ec2fc189c8b47be559d6b142 to your computer and use it in GitHub Desktop.
Prog.kiev.ua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MatrixAverageCalculator { | |
public static void main(String[] args) { | |
int[][] myArray = new int[4][6]; | |
arrayFiller(myArray); | |
int matrixAvr = calculateAverage(myArray); | |
System.out.println("AVR : " + matrixAvr); | |
} | |
private static int calculateAverage(int[][] matrix){ | |
int sum = 0; | |
for (int[] i:matrix){ | |
for (int j:i){ | |
sum += j; | |
} | |
}sum /= matrix.length +matrix[0].length; | |
return sum; | |
} | |
private static void arrayFiller(int[][] matrix) { | |
for(int i = 0;i<matrix.length;i++){ | |
for (int j=0;j<matrix[0].length;j++){ | |
matrix[i][j]=(int)(Math.random()*10); | |
System.out.print(matrix[i][j]+"\t"); | |
} | |
System.out.println(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment