Can anyone help me with the below | Selenium Forum
M
Posted on 16/08/2016
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 17/08/2016

package com.soapuitutorial.propertie;

public class ArrayCount {

public static void main(String[] args) {

int[] x = { 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 };
int count = -1;
int biggestNumber = 0;

for (int i = 1; i < x.length; i++) {
if (x[i] > biggestNumber)
biggestNumber = x[i];
}
// System.out.print(x[i]+",");
for (int i = 0; i <= biggestNumber; i++) {
for (int j = 0; j <= x.length - 1; j++) {
if (x[j] == i) {
count++;
// System.out.println(x[i] + " " + i+" "+count);
}
}
if (count < 0) {
} else {
System.out.println(i + "- Repeated " + count + " times");
}
count = -1;
}
}

}