title: Java: Variable is already defined in method main
body: <p>So I have been the following error every time I try to compile my .java file</p>
  
  <p>"error: variable max is already defined in method main(String[])
                  int max = j; "</p>
  
  <p>And I haven't been able to figure out what is the issue or how to fix it. Been stuck at it for about 2 hours now. What I'm trying to ultimately do is enter one integer into my array and sorting the digits in that integer from least to greatest to provide context.</p>
  
  <p>Here is the relevant part from my code:</p>
  
  <pre><code>   int[] wholeNumber = new int[1];
  
  
     //Sorting algorithm beginning
     int n = wholeNumber.length;
  
     System.out.println("Length of array is :" + n); //Array length displayed
  
     for(int i = 0; i &lt; 1; i++)
     {
       System.out.println("Hello!");
  
       int max = i;
  
       for(int j = i+1; j &lt; 1; j++)
       {
         if (wholeNumber[j] &gt; wholeNumber[max])
         {  
            int max = j;
         }
  
       }
       if (max != i)
       {
          wholeNumber[i] = wholeNumber[max];
          wholeNumber[max] = wholeNumber[i];
       }
  
  
  
     }
     //Sorting algorithm end
  </code></pre>