Write a program to remove duplicates from an array in Java

 /*

Write a program to remove duplicates from an array in Java

*/

import java.util.*;  

class Twentyone

{  

    public static void main(String arg[]) 

    {  

        int n , add = 0;

        Scanner in = new Scanner(System.in);

        System.out.print("\nEnter Array Size : ");

        n = in.nextInt();

        int a[] = new int[n];

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

        {

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

            a[i] = in.nextInt();

            add =add + a[i];

        }

        int arr[] = new int[add];

        System.out.println("\nAfter Removing Duplicates Numbers : ");

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

        {

            arr[a[i]]++;

            if(arr[a[i]]==1)

            {

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

            }

        }

    }

}   

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.