My code is not working as I want it to
I'm beginning to learn java and have written the following code to find the sum of the elements present in an array using what I've learnt so far... import java.util.Scanner; public class myClass { public static void main(String h[]) { Scanner s=new Scanner(System.in); int[] arr=new int[100]; System.out.print("Enter the size of the array : "); int n=s.nextInt(); for(int i=0;i<n;i++) System.out.println("Enter the "+(i+1)+" Element of arr : "+(arr[i]=s.nextInt())); //this line s.close(); int sum=0; for(int t:arr) sum+=t; System.out.println("Sum of all the elements of arr is : "+sum); } } The line I use to get the Input from the user works like so: Enter the size of the array : 5 1 Enter the 1 Element of arr : 1 2 Enter the 2 Element of arr : 2 3 Enter the 3 Element of arr : 3 4 Enter the 4 Element of arr : 4 5 Enter the 5 Element of arr : 5 Sum of all the elements of arr is : 15 I want it to Print "Enter the n element of arr : " then get the input from the user, not get the input from the user first then print what the user has already inputted. Yes, I know the scanner function can be placed after the print function to get the desired output, but I want to know if what I'm asking for is possible. Thanks in advance!