Source Code
import java.util.ArrayList;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        ArrayList<Integer> arr = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            arr.add(sc.nextInt());
        }

        for (int i = 0; i < arr.size() - 1; i++) {
            if (arr.get(i) > arr.get(i + 1)) {
                int res = arr.get(i) + arr.get(i + 1);
                arr.add(i, res);
                arr.remove(i + 1);
                arr.remove(i + 1);
                i--;
            }
        }

        for (Integer item : arr) {
            System.out.print(item+" ");
        }


    }
}
Copy
b NoraLouay
GNU G++17
0 ms
0 KB
Compilation Error