Computer Applications

Suppose x is an array of type int[] with 50 elements. Write a code segment that will count and print the frequency of number 42 in the array.

Java Arrays

8 Likes

Answer

int c = 0;
for (int i = 0; i < 50; i++) {
    if (x[i] == 42) {
        c++;
    }
}
System.out.println("Frequency of 42 = " + c);

Answered By

6 Likes


Related Questions