Question: 1. What do the following program segments print? Find the answers by tracing the code, not by using the computer. a. int n = 1;

1. 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; while (y >= 1.5) { x = x / 2; y = x + y; i++; } System.out.print(i);

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!