I am currently trying to count the number of times that a value occurs in each column of a 10 x 10 matrix with Java.
I can make it count the times in each row, but I am having a rough time with the column counts.
Thanks for your help, I am new to this site and to Java.
import java.util.Random;
import static java.lang.System.*;
public class Problem710 {
public static void main(String[] args) {
int[][] randArr = new int[10][10];
double count = 0;
for (int i = 0; i < randArr.length; ++i) {
for (int j = 0; j < randArr[0].length; ++j) {
randArr[i][j] = getRandInt(0, 1);
count += randArr[i][j];
out.print(randArr[i][j]);
}
out.println();
}
double averagePerRow = count / 10;
out.println(averagePerRow);
}
public static int getRandInt(int min, int max) {
Random rand = new Random();
return rand.nextInt(max - min + 1);
}
}