title: Input and Store names in array - Java
body: <p>I have been trying out this questions however I still cannot find the solution to it. Any help is appreciated! Thanks</p>
  
  <p>Question - Declare and create an array to store the names of four players.  Call the array pNames.</p>
  
  <p>Ask the user to input the names of the four players and store their names in the pNames array.</p>
  
  <pre><code>  Enter Name of Player 1 &gt; Johnny
    Enter Name of Player 2 &gt; Jackie
    Enter Name of Player 3 &gt; Jessie
    Enter Name of Player 4 &gt; Jeremy
  </code></pre>
  
  <p>Output a hello message to greet each player.</p>
  
  <pre><code>Hello Johnny
  Hello Jackie
  Hello Jessie
  Hello Jeremy
  </code></pre>
  
  <p>Answer: </p>
  
  <pre><code>  import java.util.Scanner;
    public class Q2 {
    public static void main(String[] args) {
  
      Scanner sc = new Scanner(System.in);
  
      String [] pNames = new String[4];
  
      for(int i = 1; i &lt;= pNames.length; i++) {
  
          System.out.print("Enter name of Player" + " " + i + " &gt; ");
  
          pNames[i] = sc.nextLine();
      }
  
      System.out.println("Hello" + " " + pNames[0]);
      System.out.println("Hello" + " " + pNames[1]);
      System.out.println("Hello" + " " + pNames[2]);
      System.out.println("Hello" + " " + pNames[3]);
  }
  </code></pre>
  
  <p>}</p>