Page 173 - ComputerScience_Class_11
P. 173
n = m * m++ + ++m;
= 15 * 15 +17
= 225 + 17
= 242
n = ++m + m++;
= 16 + 16
= 32
2. if int a=20, b=40, c;
c = ++a + --a / ++b;
= 21 + 20/41
= 21 + 0
= 21
c = a-- / --a * b++ + --b;
= 20/18 * 40 + 40
= 1 * 40 + 40
= 40 + 40
= 80
3. if int m=40, n=22;
m += m + m--/--m + n; [use of shorthand operator]
m = m+ (m + m--/--m + n)
= 40 + (40+40/38 + 22)
= 40 + (40 + 1 + 22)
= 40 + (63)
= 103
4. if int a=2, b=3, c=0;
c -= ++a + (b++ % c);
c = c - (++a + (b++ % c))
= 0 - (3 + (3 % 0)) [Error: java.lang.ArithmeticException: / by zero]
Ternary Operator:
1. int a=40, b=35, c;
c = (a==b) ? a*b : a-b;
= (40==35) ? 40*35 : 40-35
= 5
2. boolean isLeapYear = true;
int febDays = isLeapYear? 29 : 28;
= 29
3. String result=(num%2 == 0)? "Even": "Odd";
System.out.println(result);
What will be the result if num is 40?
Output: Even
Variables and Expressions 171

