Error in code because when i submit it tells wrong

import java.util.*;
public class Main {
public static void main(String args[]) {

   Scanner sc=new Scanner(System.in);
   int n=sc.nextInt();
   int arr[]=new int[n];
   for(int i=0;i<n;i++)
   arr[i]=sc.nextInt();

   for(int i=1;i<n;i++)
   {
	   int val=arr[i];
	   int j=i-1;
	   while(j>=0 && arr[j]>val)
	   {
		   arr[j+1]=arr[j];
		   j--;
	   }
	   arr[j+1]=val;
   }
   for(int i=0;i<n;i++)
   System.out.println(arr[i]);
}

}

always follow the output format

Output N space seperated integers of the sorted array in a single line.

make it
System.out.print(arr[i]+" ");
if this solves your doubt please mark it as resolved :slight_smile: