dimanche 18 septembre 2016

Why doesn't this if statement fail? [duplicate]

This question already has an answer here:

Shouldn't this code produce a divide by zero exception?

public class Testing {
    public static void main(String[] args) {
        if(6 > 5 || 5 / 0 == 0)
            System.out.println("true");
    }
}

According to the precedence rules wouldn't the 5 / 0 get executed before the 6 > 5, so I am under the impression that this code would fail due to a divide by zero exception.

I am aware that java short circuits if statements. So, if the first is true then it will evaluate to true, without even checking the second.

But, those precedence rules make it seem like the 5 / 0 would be executed first?

Aucun commentaire:

Enregistrer un commentaire