Is that a problem with BigDecimal comparison or the expected output in wrong?
import java.math.*;
import java.util.*;
class Solution{
public static void main(String []argh)
{
int res;
String temp = "";
Scanner sc= new Scanner(System.in);
MathContext mc = new MathContext(100, RoundingMode.FLOOR);
int n=sc.nextInt();
String []s=new String[n+2];
for(int i=0;i<n;i++)
{
s[i]=sc.next();
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
res = new BigDecimal(s[i], mc).compareTo(new BigDecimal(s[j], mc));
if(res == 1){
temp = s[i];
s[i] = s[j];
s[j] = temp;
}
}
}
for(int i=0;i<n;i++)
{
System.out.println(s[i]);
}
}
}
Sample Input: 9 -100 50 0 56.6 90 0.12 .12 02.34 000.000
Expected Output: 90 56.6 50 02.34 0.12 .12 0 000.000 -100
My Output: 90 56.6 50 02.34 .12 0.12 0 000.000 -100