Write a program to print K-th repeating element from an array
Printing repeating element from an array
- import java.util.HashMap;
- import java.util.Map;
- public class RepeatingElement {
- public static void main(String[] args) {
- int arr[]={1,1,1,2,3,1,6,5,7,7,8,4,4,12,2,5,8,9,7,0,6,0,6,5,3,4,0,0,1};
- Map m=new HashMap();
- for(int i=0;i<arr.length;i++){
- int total=0;
- for(int j=i+1;j<arr.length;j++){
- if(!m.containsKey(arr[i]+"")){
- if(arr[i]==arr[j]){
- total=total+1;
- }
- }
- }
- if(total>0){
- m.put(arr[i]+"", total+"");
- }
- }
- System.out.println(m);
- }
- }
Comments
Post a Comment