Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Map<Integer, Integer> map = new HashMap<Integer,Integer>();
- int[] sizeEight = {1,2,3,4,5,6,7,8};
- int[] sizeTen = {1,2,3,4,5,6,7,8,9,10};
- for(int i = 0; i < sizeEight.length; i++) {
- if(map.containsKey(sizeEight[i])) {
- int count = map.get(sizeEight[i]);
- map.put(sizeEight[i],(count + 1));
- }
- else {
- map.put(sizeEight[i],1);
- }
- }
- for(int i = 0; i < sizeTen.length; i++) {
- if(map.containsKey(sizeTen[i])) {
- int count = map.get(sizeTen[i]);
- map.put(sizeTen[i],(count + 1));
- }
- else {
- map.put(sizeTen[i],1);
- }
- }
- System.out.println("The following numbers are unique:");
- Iterator i = map.Iterator();
- while(i.hasNext()) {
- Map.Entry me = (Map.Entry)i.next();
- if(me.getValue() == 1) {
- System.out.println(me.getKey() + " ");
- }
- }
Add Comment
Please, Sign In to add comment