jeudi 26 novembre 2015

Java variable is not initialized

I've seen similar questions to this on here and I'm sorry if this seems like a duplicate but the answer to similar questions just didn't help me. So I have a method thats part of a class. Here it is:

public int min_value()
   {
       int min;

       for (int i = 0;i < size - 1;i++)
       {
           min = numbers[i];
           for (int k = 1;k < size; k++)
           {
               if (numbers[k] < min)
               {
                   min = numbers[k];
               }
               else
               {
                   min = numbers[i];
               }
           }
       }

       return min;
   }

The error says the variable min might not have been initialized. I can't understand how this can be true. I feel like there's no way the variable wouldn't be initialized out of the for loops. Please help. Thanks!

Aucun commentaire:

Enregistrer un commentaire