Dear Friends:

The if statement in the while loop Line 50 is always wrong. I don't see anything wrong in it. If a pair of same numbers are put in the array, it runs well. If there is no such a pair the array is out of boundary. Could you see and fix the problem?

Thank you very much and the best regards!

John

import java.io.*; import java.math.*; import cs1.Keyboard; public class Try{ public static void main(String[] args){ int i, limit = 11; BigInteger[]C = new BigInteger[limit]; C[1] = new BigInteger("1004"); C[2] = new BigInteger("1000"); C[3] = new BigInteger("1124"); C[4] = new BigInteger("1034"); C[5] = new BigInteger("1035"); C[6] = new BigInteger("1023"); C[7] = new BigInteger("1001"); C[8] = new BigInteger("1101"); C[9] = new BigInteger("1122"); C[10] = new BigInteger("1114"); System.out.println(" They are sorted as below:\n"); BigInteger min = new BigInteger("0"); BigInteger temp = new BigInteger("0"); int j,minindex; for( i = 1; i< limit; i++ ) { min = C[i]; minindex = i; for(j = i+1; j < limit; j++ ) if( C[j].compareTo(min) < 0 ) { min = C[j]; minindex = j; } if( min.compareTo(C[i]) < 0 ) { temp = C[i]; C[i] = min; C[minindex] = temp; } } for( i = 1; i < limit; i++ ) System.out.println(" C["+i+"] = "+C[i]); System.out.println(" Stop where same numberw occur:\n"); i = 0; while( i < limit ) { i++; if(C[i].equals(C[i-1])) { System.out.println(" C["+i+"] = C["+(i-1)+" = "+C[i]); break; } System.out.println(" C["+i+"] = "+C[i]); } System.out.println(" Done."); } }