Which value of variable a will make variable x equal to 3? Java
int x = 0;
if (a > 0)
if (a%4 == 1)
x = x + 5;
else
if (a%3 == 0)
x = x + 4;
else
x = x + 3;
else
x = x + 2;
answer is 7
when a = 7, x value become 3.
Explanation :
int x = 0;
int a = 7;
if (a > 0) True 7 > 0
if (a%4 == 1) False 7%4 = 3
x = x + 5;
else Execute this else block
if (a%3 == 0) False 7%3 = 1
x = x + 4;
else execute this else block
x = x + 3; x = 0 + 3 x = 3
else
x = x + 2;
variable a = 7, will make variable x equal to 3
Get Answers For Free
Most questions answered within 1 hours.