+ 1
Can anyone help me with this code? Why count outputs 3? In the if condition we decrease it with one right?
public class Fragments { public static void main(String[] args) { int i = 4, j = 5, k = 6, n = 7; System.out.println(i + j * k - k % n); boolean found = false; int count = 3; if (!found || --count == 0) System.out.print("found "); System.out.println(count); }}
4 odpowiedzi
+ 1
Maryam Magdy
Because !found = !false = true
So if you use or operator ( || ) and first condition get true then second condition will not be check so
Count will be 3
But if !found = false then second condition will be check and count will be 2
+ 2
You can't really decrement in the If.
Decrement usually used in some sort of loop
+ 2
!found === true on if statement
(U can't change value of count inside if(...))
--count === 2 and --count != 0
Since u have use 'or' operator which means
true || true
// true
false || true
// true
true || false
// true
false || false
//false
Here !found === true so if statement occurs
+ 2