mardi 10 juillet 2018

If Else Control Flow

I am trying to run the below code with x =10 ."X is not equal to 10!" is getting printed. but As per documentation, the else belongs to the innermost if()? Also if we replace "1==2" in the if block with 1==1 then also "X is not equal to 10!" is getting printed. Any thoughts on it ?

   if(1==2)
        System.out.println(x);
        if(x!=10)
            System.out.println("X is equal to "+x);
       else
        System.out.println("X is not equal to 10!");

Aucun commentaire:

Enregistrer un commentaire