-1

I want to get 3 strings from console and followed print the values, my problem is to get 3 input from user using for loop , but only 2 input values are received and printed here is my code.

int rockSize=sc.nextInt();
String[] rock=new String[rockSize];
for(int i=0;i<rock.length;i++)
rock[i]=sc.nextLine();
singhakash
  • 7,891
  • 6
  • 31
  • 65

1 Answers1

1

You need to swallow up the ENTER that you push after inputting your numeric value.

e.g.

int rockSize=sc.nextInt();
sc.nextLine();                         // add this
String[] rock=new String[rockSize];
for(int i=0;i<rock.length;i++)
rock[i]=sc.nextLine();
Scary Wombat
  • 44,617
  • 6
  • 35
  • 64