title: Java: Error: variable might not have been initialized
body: <p>I'm learning Java and I'm getting this error. I know this has been asked a few (a lot of) times but none of the answers seems to answer my question. The body of the code is:</p>
  
  <pre><code>String[] number = {"too small", "one", "two", "three", "four", "too large"};
  int i;
  if(num&lt;1){
      i=0;
  }
  if(num==1){
      i=1;
  }
  if(num==2){
      i=2;
  }
  if(num==3){
      i=3;
  }
  if(num==4){
      i=4;
  }
  if(num&gt;4){
      i=5;
  }
  return number[i];
  </code></pre>
  
  <p>where the variable 'num' is declared, initialized and given previously.
  The error I get is:  "Variable 'i' might not have been initialized" and pointing to the last line (return number[i];).</p>
  
  <p>The thing is, if I declare 'i' and immediately assign a value (int i=0;) the code runs fine. But if I don't assign a value I get the error EVEN if a possible value is assigned after each 'if'.</p>
  
  <p>I don't get this kind of error with C, for example.</p>
  
  <p>Thanks</p>