Java BigDecimal

  • + 0 comments

    public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        List<String> numbers = new ArrayList<>();
        Scanner scan = new Scanner(System.in);
        String linesA = scan.nextLine();
        int lines = Integer.parseInt(linesA);
        while(lines-->0){
            numbers.add(scan.nextLine());
        }
        solution(numbers);
    }
    
        static void solution(List<String> numbers){
        for(int i=0;i<numbers.size()-1;i++) {
            for(int j=i+1;j<numbers.size();j++) {
                String a = numbers.get(i);
                String b = numbers.get(j);
                BigDecimal a1 = new BigDecimal(a);
                BigDecimal b1 = new BigDecimal(b);
                int cmp = a1.compareTo(b1);
                if (cmp == -1) {
                    for(int k=j;k>i;k--) {
                        numbers.set(k, numbers.get(k-1));
                    }
                    numbers.set(i, b);
                }
            }   
            }
        numbers.forEach(System.out::println);
    }
    

    }