Question: 1. For the following program segment, fill in the tracing table below as described in the course notes. You should make a duplicate of this

1. For the following program segment, fill in the tracing table below as described in the course notes. You should make a duplicate of this table in your homework submission.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

int x = 15, y=30, z=10, a=0;

if ( x > y ) {

if (x > z) {

a = x;

}

else {

a = z;

}

}

else {

if (y > z) {

a = y;

}

else {

a = z;

}

}

System.out.println("The value is: "+a);

Statement Program State
int x = 15, y = 30, z = 10, a = 0;
x = y = z = a =
if ( x > y ) {
x = y = z = a =
if (x > z) {
x = y = z = a =
a = x;
x = y = z = a =
} else {
x = y = z = a =
a = z;
x = y = z = a =
} } else {
x = y = z = a =
if (y > z) {
x = y = z = a =
a = y;
x = y = z = a =
} else {
x = y = z = a =
a = z;
x = y = z = a =
} }
x = y = z = a =
System.out.println("The value is: " + a);
x = y = z = a =

2.For the following program segment, fill in the trace table below with values as described in the course notes. You should make a duplicate of this table in your homework submission. In addition, write a single sentence in English summarizing what this code segment does:

1

2

3

4

5

6

7

8

int n = 9431;

String output="";

while (n > 0) {

int x = n % 10;

output = output + x;

n = n / 10;

}

System.out.println("Result is: "+output);

Statement Program State
int n = 9431; String output = "";
n = output =
while ( n > 0 ) {
n = output =
int x = n % 10;
x = n = output =
output = output + x;
x = n = output =
n = n / 10;
x = n = output =
}
n = output =
System.out.println("Result is: "+output);
out = "Result is: " n = output =

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!