Computer Applications
Evaluate the following expressions if the values of the variables are a = 2, b = 3, and c = 9.
(a) a - (b++) * (--c);
(b) a * (++b) % c;
Java
Java Operators
246 Likes
Answer
(a) a - (b++) * (--c);
22
Working
a - (b++) * (--c)
⇒ 2 - 3 * 8 [∵ b++ uses current value of b in expression and then increments it, --c decrements c to 8 and then uses this 8 in the expression]
⇒ 2 - 24
⇒ -22
(b) a * (++b) % c;
8
Working
a * (++b) % c
⇒ 2 * 4 % 9 [∵ ++b increments b to 4 then uses it in the expression]
⇒ 8 % 9
⇒ 8
Answered By
139 Likes
Related Questions
What will be the output of the variable 'a'?
int a=0,b=10,c=40; a = --b + c++ + b; System.out.println(" a = " + a);
What will be the output of the following if x = 5 initially?
(a) 5* ++x;
(b) 5* x++;
If a = 5, b = 9, calculate the value of a in the following expression:
a += a++ - ++b + aThe logical operators are used in between two conditions, which results in either 'True' or 'False' depending on the outcome of different conditions. Java uses three logical operators viz. AND, OR and NOT. Your friend has created a Java snippet that contains some errors due to which he is not able to execute it.
The program snippet created by him is as shown below:
int p=11, q=12, r=15;
(a) System.out.println ((p==q) AND (q!=r));
(b) System.out.println(!(p=q));
(c) System.out.println (p!==q);
(d) System.out.println ((p!=q) OR (q!=r));
Refer to the above snippet and help him by detecting the errors so that the snippet may execute successfully.