0% found this document useful (0 votes)
14 views2 pages

Java Expression Evaluation Examples

The document provides a detailed evaluation of various Java expressions, illustrating the step-by-step operations and final results. It covers string concatenation, arithmetic operations, complex expressions involving variable manipulation, and character and integer evaluations. Additionally, it includes a variable swap example, showing the before and after states of the variables.

Uploaded by

guramritsinghop
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Java Expression Evaluation Examples

The document provides a detailed evaluation of various Java expressions, illustrating the step-by-step operations and final results. It covers string concatenation, arithmetic operations, complex expressions involving variable manipulation, and character and integer evaluations. Additionally, it includes a variable swap example, showing the before and after states of the variables.

Uploaded by

guramritsinghop
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Java Expression Evaluation Tables

1. Expression: [Link]("D" + 10 + 20 + "E" + 2 + 2);


Step Operation Evaluation Result / Value
Step 1 "D" + 10 String + int "D10"
Step 2 "D10" + 20 String + int "D1020"
Step 3 "D1020" + "E" String + String "D1020E"
Step 4 "D1020E" + 2 String + int "D1020E2"
Step 5 "D1020E2" + 2 String + int "D1020E22"
Output D1020E22

2. Expression: [Link](34.75 / 0.25 * 10 + 28.50 % 4);


Step Operation Evaluation Result / Value
Step 1 34.75 / 0.25 double / double 139.0
Step 2 139.0 * 10 double * int 1390.0
Step 3 28.50 % 4 double % int 0.5
Step 4 1390.0 + 0.5 double + double 1390.5
Output 1390.5

3. Complex Expression: x = c * a-- + (a % ++b) - (b * --c) % b;


Part Operation / Evaluation Result / Value
Explanation
Init Initial values a=20, b=40, c=50
Step 1 c * a-- 50 * 20, then a=19 1000
Step 2 ++b b becomes 41 41
Step 3 a%b 19 % 41 19
Step 4 --c c becomes 49 49
Step 5 (b * c) % b 41 * 49 = 2009 % 41 48
Final Expr 1000 + 19 - 48 971
Output 971

4. Expression using char and int values


Expression Explanation Evaluation Output
a+d 'x' + 'y' → 120 + 121 241 241
b+c 2+4 6 6
a+b 120 + 2 122 122
c+d 4 + 121 125 125
5. Variable Swap and Output
Variable Before After
x 2 5
y 5 2
a 0 Used as temp=2

Final Print Statement


Expression Result
"x=" + x + " y=" + y "x=5 y=2"
Final Output x=5 y=2

You might also like