I'm uncertain how to start writing this method in the assignment given here:
Write a method that finds the average of all elements in a matrix,
containing 2-dimensional array, of integers. The method should accept matrices of all sizes. (3x3 , 3x4, 4x3, etc.)
Any tips or suggestions would be awesome! thanks!Need help on a java programming assignment?
int matrixAverage(int[][] matrix) {
int count = 0;
int total = 0;
for(int i=0,n=matrix.length; i%26lt;n; i++) {
for(int j=0,k=matrix[i].length; j%26lt;k; j++) {
total += matrix[i][j];
count++;
}
}
int avg = total / count;
return avg;
}
// that is for integers - replace int by float/double if the matrix has other element types
Subscribe to:
Post Comments (Atom)
e currency exchange
ReplyDeleteguns for sale Australia
ReplyDeletejava programming example codes
ReplyDeletejava program code Listing the File System Roots
Are you looking for the best Nursing Assignment Help, which can assist you to score excellent marks in exams? My Assignment Help offer highly affordable rates but never compromise on the quality, that makes our services attractive to any student.
ReplyDelete