Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
// Java Coding Challenge - 09: Find out duplicate numbers using HashSet
//Title of this code //'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_45 //1, 5, 7, 54, 62, 2, 1, 54, 24, 1 import java.util.*; import java.lang.*; class Rextester { public static void main(String args[]) { int[] numbers = {1, 5, 7, 54, 62, 2, 1, 54, 24, 1}; Set<Integer> set = new HashSet<Integer>(); for (int n : numbers) { boolean unique = set.add(n); if (!unique) //(!unique == false) System.out.println("Duplicate: " + n); } } }
run
|
edit
|
history
|
help
0
fortune
test1
Tree ZigZag Traversal
Copy an array elments into another array
Simple imitation for show banners on priorities
vampires number Eckel B. Thinking in Java
3.c
Firstproject
pourWater
1a