I'm new in java programming and was learning input via scanner class. My program accepts a string array of capacity 5, and displays it back to the user.
However, the array is only accepting 4, and I can't figure out why. Any help would be appreciated.
My code
Accepting string array
String n[] = new String[5];
for (int i = 0 ; i<5 ; i++)
{
n[i] = sc.nextLine();
}
Displaying the string array
for(int i=0 ; i<5 ; i++)
{
System.out.println(n[i]);
}
The 5th string is being accepted and printed as blank for some reason, as in instead of 5 only 4 strings are being accepted and printed.