Search code examples
javavariables

Variable might not have been initiialized but should be because of an if else if


compteur = compteur + 1;
if ( compteur == 1 ) {
    petiteComm = commTotal;
    grandeComm = commTotal;
} else {
    if ( commTotal < petiteComm ) {
        petiteComm = commTotal; 
    }
    if ( commTotal > grandeComm ) {
         grandeComm = commTotal;
    }
}

it says petiteComm might not have been initiliazed but it will be because of the first if since the compteur will be at 1 the first time. I dont know what to do to fix that.


Solution

  • Why don't you just write a petiteComm = 0 before the if. That should help.