samedi 26 mai 2018

unreachable code when trying to stop executing method if condition true

Good day!

Im currently trying to stop my method if one of the digits = 0. For some reason it says "unreachable code" at the point below:

    static void method(int y) {


    int dig1 = y % 10;
    int dig2 = y / 10 % 10;  //digits of y
    int dig3 = y /100 % 10;

    if (num1 == 0);{         //if dig1 = 0, stop the method
       return; 
    }
     if (num2 == 0);{      // unreachable code, but why?
        return;
     }
      .... and so on

How come it says unreachable code even if the condition is not true? y = numbers from 122 - 133 and the only number who is supposed to stop the method is 130 because of the 0. Could someone be this kind and explain it to me please? Thanks!

Aucun commentaire:

Enregistrer un commentaire