Table of Contents

52

I am trying to write a code which will find the duplicate value in an arrayLisr. So, far I have written below code:

package – task // public class- DupNum

package task;

import java.util.ArrayList;
import java.util.List;

public class DupNum {

    public static void main(String[] args) {
        //Scanner input = new Scanner(System.in);
        //System.out.println("How Many Numbers You want to Enter:");
        //int n = input.nextInt();

        List<Integer> number = new ArrayList<>();
        number.add(1);
        number.add(11);
        number.add(11);
        number.add(2);
        number.add(6);
        number.add(2);
        number.add(5);
        number.add(6);
        number.add(2);
        number.add(2);
        number.add(22);

        for (int i = 0; i < number.size(); i++) {
            System.out.println(number.get(i) + " ");
        }
        System.out.print("Duplicates: ");
        int k=number.size();
        int l=0;

        for (int i = 0; i < k-1; i++) {
            for (int j = i + 1; j < number.size(); j++) {
                if (number.get(i)==(number.get(j)) ) {
                    l++;
                    number.remove(j);

                }
                

            }
            if(l>0)System.out.print(" "+number.get(i) );
            l=0;
        }
        System.out.println(" ");

    }
}

Programmer- Mustahid Hasan

Student of Computer Science Engineering Student
Daffodil International University
Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn
Share on pinterest
Pinterest
Share on whatsapp
WhatsApp
Share on email
Email
Md. Nurnobi Hosen
Md. Nurnobi Hosen

Student of Computer Science and Engineering at Daffodil International University,Main Campus ,Dhanmondi.
Web and App Developer also expart of wordpress customization

All Blog Posts »
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x