Can you expalin the code for the below | Selenium Forum
M
Posted on 16/11/2015
Suppose there is an integer array holding following elements:
1,3,4,5,6,3,2,4,6,7,9,4,12,3,4,6,8,9,7,6,43,2,4,7,7,5,2,1,3,4,6,311,1

Write a program which prints which each number from array and the times it has been repeated in array
Fox eg
1- Repeated 3 times
4- Repeated 6 times

M
Replied on 16/11/2015

int[] arr = { 1, 3, 4, 5, 6, 3, 2, 4, 6, 7, 9, 4, 12, 3, 4, 6, 8, 9, 7,
6, 4, 3, 2, 4, 7, 7, 5, 2, 1, 3, 4, 6, 3, 1, 1, 1 };

for (int i = 1; i < 9; i++) {
int k = 0;
for (int j = 0; j < arr.length; j++) {

if (arr[j] == i) {
k++;
}
}

if (k == 3) {
System.out.println("repeated 3 times" + i);
}
if (k == 6) {
System.out.println("repeated 6 times" + i);
}
}
}