title: Storing user input to an array java
body: <p>I know this question have been asked a lot of times, but I still could not solve the problem. The problem is that I have to store an user input and print out a value.</p>
  
  <p>For example, there are 4 people, person1, person2, person3 and person4. If I vote for person1, the vote number of person1 becomes 1 and the others remain 0. Then if I vote for person2, the vote number of person2 becomes 1 and person1 is also 1. </p>
  
  <p>I can compile the code. But then if I vote for person1, the output becomes 4. and if I then vote for person2, the output of person2 becomes 4 and vote for person1 went back to 0. I am a complete beginner in programming and got stuck at this program for 4 whole days so any help is greatly appreciated. Thank you very much in advance. </p>
  
  <pre><code>import javax.swing.*; // import swing lib for i/o
  public class Arrays4
  {
  public static void main (String[] args)
  {
      voteperson();
      voterepeat();
      System.exit(0);
  } // end method main
  
  public static int voteperson()
  {
      // Initialize String Arrays
      String[] person = new String[4];
      person[0] = "person1";
      person[1] = "person2";
      person[2] = "person3";
      person[3] = "person4";
  
      // Initialize int Arrays
      int[] votescount = new int[4];
      votescount[0] = 0;
      votescount[1] = 0;
      votescount[2] = 0;
      votescount[3] = 0;
  
      // Declare String Variables
      String userinput;
      userinput = JOptionPane.showInputDialog
      ("Please tell us which painting you think is the best."+"\n"+
      "Vote 1 "+person[0]+"\n"+
      "Vote 2 "+person[1]+"\n"+
      "Vote 3 "+person[2]+"\n"+
      "Vote 4 "+person[3]);
  
      int answer = Integer.parseInt(userinput);
  
      int i;
      for (i=0; i&lt;votescount.length; i++)
      {
          if (answer == 1)
          {
              votescount[0] = votescount[0]+1;
          }
          else if (answer == 2)
          {
              votescount[1] = votescount[1]+1;
          }
          else if (answer == 3)
          {
              votescount[2] = votescount[2]+1;
          }
          else if (answer == 4)
          {
              votescount[3] = votescount[3]+1;
          }
          else
          {
  
          }
      } // end for loop
  
      JOptionPane.showMessageDialog
      (null, "The current votes are" + "\n" +
      votescount[0] + " :" + person[0] + "\n" +
      votescount[1] + " :" + person[1] + "\n" + 
      votescount[2] + " :" + person[2] + "\n" +
      votescount[3] + " :" + person[3]);
  
      return 0;
  }
  public static void voterepeat()
  {
      for (int j=1; j&lt;=4; j++)
      {
          int repeat;
          repeat = voteperson();
          System.out.println(j);
      }
  }
  }
  </code></pre>