Java BigDecimal

  • + 0 comments

    import java.io.; import java.util.; import java.math.BigDecimal;

    public class Solution {

    public static void main(String[] args) {
    
        Scanner sc= new Scanner(System.in);
    int n=sc.nextInt();
    // System.out.println(n);
    String[] s=new String[n];
    for(int i=0;i<n;i++){
        s[i]=sc.next();
    }
    sc.close();
    Arrays.sort(s, new Comparator<String>() {
    @Override
    public int compare(String a, String b) {
        BigDecimal decimal1 = new BigDecimal(a);
        BigDecimal decimal2 = new BigDecimal(b);
        return +decimal2.compareTo(decimal1);
        // return decimal2.compareTo(decimal1); for Asscending order write -
    }
    

    });

    for(int i=0;i<n;i++)
    {
        System.out.println(s[i]);
    }
        }
    }