Java buffer logic behavior

This is my first post, so please forgive any protocol errors.

My question is simply trying to understand what happens with the following Java code. I fully understand that using parentheses will clarify everything, but the result seems to fly away before the convention regarding the order of Java operations.

public class Tester
{
   public static void main(String[] args)
   {
    int total=9, num=13;
    if (total>4 || ++num>15 && total>0)
    {
           System.out.println("short");
    }
    System.out.println(num);
   }
}

Output: Short 13

, ++ num . , . . , & &. && ||, ... ++ num . . , , || , shortciruiting++ num, , & &, , . , ? ?

, .

+5
5

/ ( )... Java - . , , , .

&& || - - . " " , , .


...

total > 4 || ++num > 15 && total > 0

total > 4 true, true, if , .

total 4, (total > 4) false , , (++num > 15 && total > 0).

num 15, AND (++num > 15) true , , , , AND (total > 0), , true. total > 0 , false.

, , .

if (total > 4) {
  System.out.println("short");
} else {
  if (++num > 15) {
    if (total > 0) {
      System.out.println("short");
    }
  }
}
System.out.println(num);

Java Java.

+6

(||), java; ( , ). , , (||), ( - , (& &)), . , 4, (- ||) true if ; , , ,

+4

, . total > 4 true, true. , ||. , C, ++ Javascript ( ). " ".

, (, || && ( -) null) (, ). , .

+3

total > 4 || (++ num > 15 && total > 0). SQL. && 2 , , . total = 9 > 4 ++ num = 14 < 15 total = 9 > 0, true (false && true) = true. "short" num, 13.

Hope my answer helps you. If I am wrong, please correct me.

0
source

I think this does not change the actual value of the variable when used in an if condition. The value stored in memory remains unchanged. it's like num + 1> 15 in the expression

0
source

All Articles