What do the following program segments print? Find the answers by tracing the code, not by using

Question:

What do the following program segments print? Find the answers by tracing the code, not by using the computer.

a. int n = 1;
for (int i = 2; i < 5; i++) { n = n + i; }
System.out.print(n);

b. int i;
double n = 1 / 2;
for (i = 2; i <= 5; i++) { n = n + 1.0 / i; }
System.out.print(i);

c. double x = 1;
double y = 1;
int i = 0;
do
{
y = y / 2;
x = x + y;
i++;
}
while (x < 1.8);
System.out.print(i);

d. double x = 1;
double y = 1;
int i = 0;
while (y >= 1.5)
{
x = x / 2;
y = x + y;
i++;
}
System.out.print(i);

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: