import java.util.Scanner;
public class test{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("Enter maximum number : ");
int items = input.nextInt();
String arr[] = new String[items];
int x = 0;
while(x < items)
{
System.out.println("Enter item " + x + ":");
arr[x] = input.nextLine();
x++;
}
}
}
On my code, First is I asked maximum number in an array index and store to arr[]. Now, I find error when I press enter and it displayed "Enter item 0" and "Enter item 1". It displayed index arr[1] . What should be displayed is "Enter item 0" only at my first press of enter. Does anybody know about this?
Thanks