code is working but not satisfying conditions
package com.codegym.task.task06.task0622;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/*
Ascending numbers
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int temp,n;
n = Integer.parseInt(reader.readLine());
int a[] = new int[n];
for(int i = 0; i<n; i++)
{
a[i] = Integer.parseInt(reader.readLine());
}
for(int i = 0; i < n; i++)
{
for(int j = i+1; j < n; j++)
{
if(a[i]>a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
for(int i = 0; i<n-1;i++)
{
System.out.println(a[i]);
}
System.out.println(a[n-1]);
//write your code here
}
}