In this java program, i am trying to take no of elements (n) for my String array, and then iterating that much times to insert values in my String array. But insertion does not reach till end and does not execute the last iteration. For example if n=3 then it should iterate three times(0,1,2) for insertion but it does only twice. Please help to understand.enter code here
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String[] arr=new String[60];
System.out.println("Enter no of elements");
int n=sc.nextInt();
for(int i=0;i<n;i++) {
arr[i]=sc.nextLine();
}
for(int i=0;i<n;i++)
System.out.println(arr[i]);
}
}