Part 2: Fill-in FindDuplicateCount.java You are given an integer array (arr) declared in the program. Count all the numbers that are repeated in the array entries. If there are no duplicates then your program should output should print out according to the expected output below. If there is only one duplicate then the message should state that. Finally, for two or more duplicates then the output should match the expected output. Your solution should use loops (hint: nested loops) and should work for any integer array

Respuesta :

Answer:

//Program is written in Java Programming Language

// Comments are used for explanatory purpose

//Program starts here

import java.util.*;

public class FindDuplicateCount

{

public static void main (String [] args)

{

Scanner input = new Scanner(System.in);

//Declare size of array

int size.

//Input array size.

size = input.nextInt();

//Declare array

int arr[] = new int[n];

int i, j, size, count = 0;

/* Input elements in array */

System.out.println("Enter elements in array : ");

for(i=0; i<size; i++)

{

arr[I] = input.nextInt();

}

/*

* Find all duplicate elements in array

*/

for(i=0; i<size; i++)

{

for(j=i+1; j<size; j++)

{

/* If duplicate found then increment count by 1 */

if(arr[i] == arr[j])

{

count++;

break;

}

}

}

System.out.print("\nTotal number of duplicate elements found in array = "+ count);

}

}

ACCESS MORE