The for loops work just fine! The issue arises at temp part... "number(k) now found". how to solve this.

package com.codegym.task.task06.task0622;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.*;
import java.util.*;
/*
Ascending numbers
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<Integer> number = new ArrayList<Integer>(5);
for (int i=0; i<5; i++){
String num = reader.readLine();
int Num = Integer.parseInt(num);
number.add(Num) ;
}
ArrayList<Integer> temp = new ArrayList<Integer>(5);
for(int k = 0;k <number.size(); k++) {
for(int j = 1; j<number.size(); j++) {
if (number.get(k) < number.get(j))
temp = number(k);
number(k) = number(j);
number(j) = temp;
}
}
Arrays.sort(numbers);
for(int j = 0; j<numbers.length; j++){
System.out.println(Arrays.toString(list));
}//write your code here
System.out.println(number);
}
}

number.sort(), not Array.sort(number);number.sort(Comparator.naturalOrder());(there is also one for reverseOrder) Collections.sort() and Arrays.sort() are the same thing, except one takes a List(like an ArrayList) while the other only takes an Array. These use a Comparator too, but defaults to naturalOrder. With Arrays.Sort you are not able to change the order with Arrays of primitives, like ints. You would need an Integer[] to change the order. Collections.sort() wont have that problem because you can't make primitive's lists. If you triedArrayList<int> temp = new ArrayList<>(), the code would fail.