Java Program to print the duplicate elements of an array

 /*

Java Program to print the duplicate elements of an array

*/

import java.util.*;

class Twentythree

{

    public static void main(String arg[])

    {

        Scanner in = new Scanner(System.in);

        System.out.print("Enter Array Size : ");

        int n = in.nextInt();

        int arr[] = new int[n];

        for(int i=0; i<n; i++)

        {

            System.out.print("Enter Number of Arr[" + i + "] : ");

            arr[i] = in.nextInt();

        }

        for(int i=0; i<n; i++)

        {

            System.out.println("Arr[" + i + "] Is : " + arr[i]);

        }

        System.out.print("\nDuplicate Value Is : ");

        for(int i=0; i<n; i++)

        {

            for(int j=i+1; j<n; j++)

            {

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

                {

                    System.out.print(arr[j] + ",");

                }    

            }

        }

        System.out.print("\n");

    }

}

More Information on our channel Programmer Community

please like , share and subscribe to get notifications of new videos....

To understand this program video will coming soon on our you tube channel



Comments

Popular posts from this blog

Design and Develop a java program to read marks of a student and print the total and average of marks using scanner class.

Write a Java program to convert seconds to hour, minute and seconds.

Write a Java program to print the ascii value of a given character.