Java BigDecimal

  • + 4 comments

    Sort numbers with bubble sort, and don't lose zeros. Actually we don't change String array.

        for (int i = 0; i < s.length-2; i++) {
            for (int j = 1; j < (n-i); j++) {
                BigDecimal sj = new BigDecimal(s[j]);
                BigDecimal sj1 = new BigDecimal(s[j-1]);
                if(sj.compareTo(sj1) == 1){
                    String temp = s[j];
                    s[j] = s[j-1];
                    s[j-1] = temp;
                }
            }       
        }