The document contains 21 programming questions and answers related to operators such as increment, decrement, addition and multiplication. Some key points:
1) Questions involve evaluating expressions and determining the output/value of variables after applying various operators like ++, --, +=, etc.
2) Sample questions include determining the value of variables a, b, c, x, y after expressions like a+=a++ + ++a;
3) Answers walk through the order of operations, showing the step-by-step work to arrive at the final value.
4) Concepts covered include pre/post increment/decrement, operator precedence and order of evaluation.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
33 views12 pages
Java Evaluation
The document contains 21 programming questions and answers related to operators such as increment, decrement, addition and multiplication. Some key points:
1) Questions involve evaluating expressions and determining the output/value of variables after applying various operators like ++, --, +=, etc.
2) Sample questions include determining the value of variables a, b, c, x, y after expressions like a+=a++ + ++a;
3) Answers walk through the order of operations, showing the step-by-step work to arrive at the final value.
4) Concepts covered include pre/post increment/decrement, operator precedence and order of evaluation.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12
1.
What will be the output for the
following program segment? int a=0,b=30,c=40; a= --b + c++ +b; System.out.println("a="+a); Ans: 29 + 40 + 29 = 98 2.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 Ans: (a) -22 (b) 8 3. If a=5, b=9, calculate the value of a+=a++ - ++b +a. Ans: 5 + 5 - 10 + 6 = 10 - 10 + 6 =6 4. What will be the output of the following code? int k=5, j=9; k+=k++ - ++j + k; System.out.println("j="+j); System.out.println("k="+k); Ans: j=10 k=6 5. What is the result produced by 2- 10*3+100/11? Ans: 2-10*3+100/11 = 2 - 30 + 9 = -28 + 9 = -19 6. int x=20, y=10, z; What is the value of z in z = ++x * (y--) - y? Ans: z = ++x * (y--) - y = 21 * 10 - 9 = 210 - 9 = 201 7. What will be the output of the following code segment? int a=15, b=21, c; What is the value of c in c= ++a + b++ * a++ - b; Ans: 16 + 21 * 16 - 22 = 16 + 336 - 22 = 352 - 22 = 330 8. Evaluate the value of the following expression if x=9 and y=19 initially: (++x) + y + (x++) + (++y) + x + (y++) + 29. Ans: 10 + 19 + 10 + 20 + 11 + 20 + 29 = 119 9. If x=9, y=5, determine the value of x after executing: x+=(++x) % y; Ans: 9 + 10 % 5 =9+0 =9 10. If a=6, b=2 and c=3.5, then evaluate x and y as follows: (i) x = a - (b++) * (-c); (ii) y = (++b) * a - b; Ans: x = 13.0 y = 15 11. If x = 20, determine the value of: x += x * x - ((--x) * (x--)) Ans: 20 + 20 * 20 - (19 * 19) = 20 + 400 - 361 = 420 - 361 = 59 12. If x = 4, the determine the value of (x++) + (++x) Ans: 4 + 6 = 10 13.Given: x += x++ + ++x + --x Find the value, when x=5. Answer x = 5 + (5 + 7 + 6) x = 5 + 18 x = 23 14.What will be the output of the following code? int k=5,j=9; k += k++ - ++j + k; System.out.println("k="+k); System.out.println("j="+j); Answer k+= k++ - ++j + k ⇒ k = k + (k++ - ++j + k) ⇒ k = 5 + (5 - 10 + 6) ⇒k=5+1 ⇒k=6
k=6 j=10
15.If int y =10 then find int z = (++y*(y++
+ 5)); Answer z = (++y * (y++ + 5)) ⇒ z = (11 * (11 + 5)) ⇒ z = (11 * 16) ⇒ z = 176 16.Give the output of the following expression: a += a++ + ++a + --a + a--; when a = 7; Answer a+= a++ + ++a + --a + a-- ⇒ a = a + (a++ + ++a + --a + a--) ⇒ a = 7 + (7 + 9 + 8 + 8) ⇒ a = 7 + 32 ⇒ a = 39
17.What is the value of y after the
execution? y += ++y + y-- + --y; when int y=8 Answer y+= ++y + y-- + --y ⇒ y = y + (++y + y-- + --y) ⇒ y = 8 + (9 + 9 + 7) ⇒ y = 8 + 25 ⇒ y = 33 18.int a=3, b=7; a*=++a + --b + a--; System.out.println (a+","+b);