"Write a Freq. method that receives data from an array A that has integers between 0 and 0, generates a vector with the occurrences of each integer between 0 and x. that takes a vector of integers and returns the largest element of the vector.Form the main module, which fills an array with only values between 0 exe and displays which value was the most frequent (call the / strong>, major and leMatrix ). "
I've already assembled the array by sorting the numbers, now I'm trying to create the FrequencyFactory method. I have two questions:
1) How do I get the algorithm to "skip" the counting of numbers that have already been counted? For example, if the matrix is: (0 0 1); (230); (1 2 3), the program will count 0 three times, then when it goes next, it will count 0 three times again.
2) How to declare the vector that will store the counted frequencies without knowing its size? I thought about creating a string and then converting it to integer vector, but repeating the frequency count would still be a problem. I also thought about leaving the array elements in ascending order to find the highest value. By this I would know the size of the vector that stores the frequencies. But I'm not able to sort using Arrays.sort () ...
public class Freq_Maior {
static Scanner ent = new Scanner(System.in);
public static void main(String[] args) {
System.out.print("Digite o número de linhas e colunas da matriz: ");
int m = ent.nextInt();
int n = ent.nextInt();
System.out.print("Digite o valor máximo do intervalo usado para preencher a matriz: ");
int x = ent.nextInt();
int [][] A = new int[m][n];
leMatrizR(A, x);
}
// método para ler a matriz
public static void leMatrizR(int matriz[][], int a) {
Random rnd = new Random();
for (int i=0; i<matriz.length; i++) {
for (int j=0; j<matriz[0].length; j++) {
matriz[i][j] = rnd.nextInt(a+1);
}
}
}
public static void Freq(int matriz[][]) {
????
}
}