title: Java: Variable is already defined in method
body: <p>I am trying to make a program which makes a random number between 1000-9999 with no repeating numbers. The rules are I have to label the random number as a String, and then use a while loop to figure out if any of the numbers repeat.</p>
  
  <pre><code>//generating random number
  double answer1 = (Math.random() * 9000)+1000;
  
  //converting answer
  int answer2 = (int)answer1;
  String answer = answer2 + " ";
  
  //Labeling arrays
  answer.toCharArray();
  
  //**NEW** checking random number
  while (answer.charAt(0) == answer.charAt(0)
         || answer.charAt(0) == answer.charAt(1)
         || answer.charAt(0) == answer.charAt(2)
         || answer.charAt(0) == answer.charAt(3)
         || answer.charAt(1) == answer.charAt(1)
         || answer.charAt(1) == answer.charAt(2)
         || answer.charAt(1) == answer.charAt(3)
         || answer.charAt(2) == answer.charAt(2)
         || answer.charAt(2) == answer.charAt(3)
         || answer.charAt(3) == answer.charAt(3)); //you have my apologies
  {
      ////generating random number
      double answer1 = (Math.random() * 9000)+1000;
  
      //converting answer
      int answer2 = (int)answer1;
      String answer = answer2 + "
  }
  </code></pre>
  
  <p>I know the while parameters are extremely long, but it was necessary to make sure none of the numbers repeated. I assumed that I could regenerate a new random number and test it again in the while loop, but I get the error that variables answer1, answer, and answer2 are already defined in my main method. Does anyone have a tip as to what I can do to generate a new random number until none of the numbers repeat?</p>