java - find pairs in int [] b;? -


how find pairs of numbers chosen b, example have

int [] b = {1,2,3,5,4,3,2,1,1}; 

and need print pairs found in integer array , position @ keep in mind tried compare them this

for (int = 0; < ia.length; i++) {     number = 0;     (int j = 0; j < ia.length; j++) {         if (ia[i] == ia[j]) {             number++;         }     }     if (number%2==0) {         system.out.println("found pairs @  ia["+i+"] = "+ia[i] );     } } 

but problem keeps comparing other numbers if have number can found 3 times first time compare , it's not pair second time not compared previous value instead of 3 find 2 , it's pair

thank taking time in responding question

you have few errors in there, here go:

int[]ia={1,2,1,2,2};         (int = 0; < ia.length; i++) {             int number = 0;             (int j = 0; j < ia.length; j++) {                 if (ia[i] == ia[j]) {                     number++;                 }             }             if (number%2==0) {                 system.out.println("found pairs @  ia["+i+"] = "+ia[i] );             }         } 

everyone starded somewhere....


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -