title: get input from user and store it in String Array in Java
body: <p>i write one program that get input from user as "Enter number of students:" then add the student names into it and print it in console. I write one code that run fine but problem is the loop is already ramble one time the code is not properly working i also want to know that how to get inputs using command line argument without <strong>Scanner</strong> and store it in <strong>String Array</strong></p>
  
  <p>Current Output is like that
  <a href="https://i.stack.imgur.com/iGmaG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iGmaG.png" alt="enter image description here"></a></p>
  
  <p>Here is my code please help and i am in learning phrase of Java</p>
  
  <pre><code>import java.util.Scanner;
  
  public class StringScanner
  {
    public static void main(String args[])
    {
      Scanner in = new Scanner(System.in);
  
      //get the input for number of students:
      System.out.println("Enter The number of students:");
      int totalstudents = in.nextInt();
  
      //store into String array
  
      String studentname[] = new String[totalstudents];
  
      for(int i = 0; i &lt; studentname.length;i++)
      {
          System.out.println(i);
          System.out.println("Enter Student Names: ");
          studentname[i] = in.nextLine();
      }
      for(String names:studentname)
      {
          System.out.println(names);
      }
  }
  </code></pre>
  
  <p>}</p>