i)
int a=5;
int p= ++a+ --a + a++ + a-->
System.out.println(p);
ii)
int a=4;
int r= att + --a + ++a + --a;
System.out.println(r);
int a=6;
int s= Ha + --a + att + --a;
System.out.println(s);
iv)
int a=7;
int u= a++ + a-- + a++ + a-- +a;
System.out.println(u);
Answers
Question 1 Solution:
Given C∅de:
int a = 5;
int p = ++a + --a + a++ + a--
System.out.println(p);
Output:
22
Solution:
→ a = 5 (Given)
→ p = ++a + --a + a++ + a--
→ p = 6 + --a + a++ + a-- (a becomes 6, pre-increment)
→ p = 6 + 5 + a++ + a-- (a becomes 5, pre-decrement)
→ p = 6 + 5 + 5 + a-- (a is 5, post-increment)
→ p = 6 + 5 + 5 + a-- (a becomes 6)
→ p = 6 + 5 + 5 + 6 (a is 6, post-decrement)
→ p = 6 + 5 + 5 + 6 (a becomes 5)
→ p = 22
Output: 22
Question 2 Solution:
Given C∅de:
int a = 4;
int r = a++ + --a + ++a + --a;
System.out.println(r);
Output:
21
Solution:
→ a = 5 (Given)
→ r = a++ + --a + ++a + --a
→ r = 5 + --a + ++a + --a (a is 5, post-increment)
→ r = 5 + --a + ++a + --a (a becomes 6)
→ r = 5 + 5 + ++a + --a (a is 5, pre-decrement)
→ r = 5 + 5 + 6 + --a (a is 6, pre-increment)
→ r = 5 + 5 + 6 + 5 (a is 5, pre-decrement)
→ r = 21
Output: 21
Question 3 Solution:
Given C∅de:
int a = 6;
int s = ++a + --a + a++ + --a
System.out.println(s);
Output:
23
Solution:
→ a = 6 (Given)
→ s = ++a + --a + a++ + --a
→ s = 7 + --a + a++ + --a (a is 7, pre-increment)
→ s = 7 + 6 + a++ + --a (a is 6, pre-decrement)
→ s = 7 + 6 + 6 + --a (a is 6, pre-increment)
→ s = 7 + 6 + 6 + --a (a becomes 5)
→ s = 7 + 6 + 6 + 4 (a is 4, pre-decrement)
→ s = 23
Output: 23
Question 4 Solution:
Given C∅de:
int a = 7;
Output:
37
Solution:
→ a = 7
→ u = a++ + a-- + a++ + a-- + a
→ u = 7 + a-- + a++ + a-- + a (a is 7, post-increment)
→ u = 7 + a-- + a++ + a-- + a (a becomes 8)
→ u = 7 + 8 + a++ + a-- + a (a is 8, post-decrement)
→ u = 7 + 8 + a++ + a-- + a (a becomes 7)
→ u = 7 + 8 + 7 + a-- + a (a is 7, post-increment)
→ u = 7 + 8 + 7 + a-- + a (a becomes 8)
→ u = 7 + 8 + 7 + 8 + a (a is 8, post-decrement)
→ u = 7 + 8 + 7 + 8 + a (a becomes 7)
→ u = 7 + 8 + 7 + 8 + 7
→ u = 21 + 16
→ u = 37
Output: 37
•••♪