An array of integers logical question (a) in addition to the two figures, other figures have emerged twice, please write a program to find these two figures appear only.

Test Package; 
Import Classes in java.util. * ; 

public  class test17 {
     public  static  void main (String [] args) {
         // an array of integers in addition to the two figures, other numbers appear twice.
        // Please write program to find these two numbers appear only once. 
        int [] = {INTS . 1 , . 1 , 2 , . 5 , . 5 , . 6 , . 3 , . 3 }; 
        the Map <Integer, Integer> Map = new new the HashMap <Integer, Integer> ();
         for ( int I = 0;i<ints.length;i++){
            if (map.containsKey(ints[i])){
                int i1 = map.get(ints[i]) + 1;
                map.put(ints[i],i1);
            }else {
                map.put(ints[i],1);
            }
        }
        ArrayList list = new ArrayList();
        for (int i=0;i<ints.length;i++){
            if (map.get(ints[i])==1){
                List.add (INTS [I]); 
            } 
            IF (. map GET (INTS [I]) == 2 ) {
                 Continue ; 
            } 
        } 
        . the System OUT .println (List); 
    } 
} 
Explanation:
First we will set with map each digital access to the collection, number of key, value for the number of occurrences of the result is:
{a = 2, 1 = 2, 3 = 2, 5 = 2, 6 = 1}
, but only because the map set in accordance with take the value of the key features that we want to take a number appears, we will list each value set as as a key, the value is equal to a value into the list.

 

Guess you like

Origin www.cnblogs.com/shiji7/p/11961952.html