Why do i get this value in logical operator and java? -
i have question value of variable x. hope next output
false , valor de x = 1
but
false , valor de x = 0
why?
thnks
class numero{ public static void main(string... args){ int x = 0; if((x>1) && (x++ >=0) & (x++>=1)) system.out.println("true , " + "valor de x = " + x); else system.out.println("false , " + "valor de x = " + x); } }
since using && operator, stop evaluating conditions on first failing condition. in case stop reading other conditions after having x>1 = false. if want conditions evaluated no matter if fails @ condition, utilize single & operator
public static void main(string... args){ int x = 0; if((x>1) & (x++ >=0) & (x++>=1)) system.out.println("true , " + "valor de x = " + x); else system.out.println("false , " + "valor de x = " + x); } java
No comments:
Post a Comment