package array;
import java.util.Arrays;
public class learning_program1 {
public static void main(String[] args) {
int arr[]= {1,2,3,4,10,20,30,6,6,5,4,5,5,2};
Arrays.sort(arr);
for(int i = 0; i < arr.length; i++)
{
int count =0;
int flag=0;
for(int j=i+1; j<arr.length; j++)
{
while(arr[i] == arr[j])
{
count++;
j++;
flag=1;
}
break;
}
if(flag==1)
{
System.out.println("the repeated values " + arr[i] + " is " +count);
}
}
}
}
Output:
the repeated values 2 is 1
the repeated values 4 is 1
the repeated values 5 is 2
the repeated values 5 is 1
the repeated values 6 is 1
my question is i am getting the output but 5 is repeating twice
Mapor aHashMap. Keep the digit in the array as a key insideMaporHashMapand its count as value.