Last active
October 3, 2022 16:07
-
-
Save kapilraj2436/f201c8d02a505ed19039031b787f1d4a to your computer and use it in GitHub Desktop.
Program to find Duplicate elements in given Array.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class FindDuplicateNumberInSeries | |
{ | |
public static void main(String[] args) | |
{ | |
Scanner scan= new Scanner(System.in); | |
int n = scan.nextInt();//Enter last number (Must have greater then 10) | |
List<Integer> numbers = new ArrayList<Integer>(); | |
for(int i=0;i<n-1;i++) | |
{ | |
numbers.add(i); | |
} | |
numbers.add(10); | |
getDuplicateNumber(numbers); | |
} | |
private static void getDuplicateNumber(List<Integer> numbers) | |
{ | |
List<Integer> _duplicateNumbers = numbers; | |
System.out.println("_duplicateNumbers.size(): " +_duplicateNumbers.size()); | |
for(int i=0;i<_duplicateNumbers.size();i++) | |
{ | |
int temp = _duplicateNumbers.get(i); | |
for(int j=i+1;j<_duplicateNumbers.size();j++) | |
{ | |
if(temp == _duplicateNumbers.get(j)) | |
{ | |
System.out.println("Duplicate Number is : "+temp); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment