Find the duplicate elements and count of every duplicate element in array ?
Duplicate elements and counts.
package com.tech.array; public class DuplicateElement { public static void main(String args[]) { int[] a = { 1, 2, 3, 4, 5, 6, 5, 6, 2, 3 }; for (int i = 0; i <= a.length - 1; i++) { int count = 1; for (int j = i + 1; j <= a.length - 1; j++) { if (a[i] == a[j]) { count++; } } if (count != 1) System.out.println("Element is : " + a[i] + " Present in array : " +count+" times"); } } }
Element is : 2 Present in array : 2 times Element is : 3 Present in array : 2 times Element is : 5 Present in array : 2 times Element is : 6 Present in array : 2 times
post a comment