4 comments:

  1. import java.util.Scanner;
    class Duplicate
    {
    public static void main(String args[])
    {
    int temp;
    Scanner scan=new Scanner(System.in);
    System.out.println("How many number you want to add");
    int n=scan.nextInt();
    int d=0;
    int ar[]=new int[n];
    System.out.println("Enter Numbers");
    for (int i=0;i<n;i++)
    {
    ar[i]=scan.nextInt();
    }
    for(int j=0;j<n;j++)
    {
    for(int i=j+1;i<n;i++)
    {
    if(ar[j]==ar[i])
    {
    ar[d]=ar[j];
    d++;
    break;
    }
    }
    }
    System.out.print("Duplicate value removed ");
    for (int i=d;i<n;i++)
    {
    System.out.print(ar[i]+" ");
    }
    }
    }

    ReplyDelete
  2. public class RemoveDuplicateInArrayExample{
    public static int removeDuplicateElements(int arr[], int n){
    if (n==0 || n==1){
    return n;
    }
    int[] temp = new int[n];
    int j = 0;
    for (int i=0; i<n-1; i++){
    if (arr[i] != arr[i+1]){
    temp[j++] = arr[i];
    }
    }
    temp[j++] = arr[n-1];
    // Changing original array
    for (int i=0; i<j; i++){
    arr[i] = temp[i];
    }
    return j;
    }

    public static void main (String[] args) {
    int arr[] = {10,20,20,30,30,40,50,50};
    int length = arr.length;
    length = removeDuplicateElements(arr, length);
    //printing array elements
    for (int i=0; i<length; i++)
    System.out.print(arr[i]+" ");
    }
    }

    ReplyDelete
  3. import java.util.Scanner;
    class Delete2{
    public static void main(String arr[]){
    Scanner obj=new Scanner(System.in);
    int n,k,i,j;
    System.out.println("enter the value of n");
    n=obj.nextInt();
    int ar[]=new int[n];
    System.out.println("enter the array elements");
    for(i=0;i<n;i++)
    ar[i]=obj.nextInt();
    for(i=0;i<n;i++){
    for(j=i+1;j<n;){
    if(ar[j]==ar[i]){
    for(k=j;k<n-1;k++)
    ar[k]=ar[k+1];
    n--;
    }
    else
    j++;
    }
    }
    for(i=0;i<n;i++)
    System.out.println(ar[i]);
    System.out.println("the above array is the required array");
    }

    }

    ReplyDelete
  4. import java.util.Scanner;
    class Duplicate1{
    public static void main(String ar[]){
    int temp,dup=0;
    Scanner scan=new Scanner(System.in);
    System.out.println("Numbers you want to add");
    int n=scan.nextInt();
    int a[]=new int[n];
    System.out.println("Enter the values");
    for (int i=0;i<n;i++){
    a[i]=scan.nextInt();
    }
    for(int j=0;j<n;j++){
    for(int i=1;i<=n;i++){
    if(a[j]==a[i]){
    a[dup]=a[j];
    dup++;
    break;
    }
    }
    }
    System.out.print("Duplicate value is removed ");
    for (int i=0;i<n;i++){
    System.out.print(a[i]+" ");
    }
    }//End of main
    }//End of class

    ReplyDelete