Loops (with solutions)

 

 

Indicate the output that will be produced for each exercise. For questions 1 to 5, assume the following declarations are made just before each exercise. That is, assume these initializations are in effect at the beginning of each problem:

(The outputs are given on the right.)

 

 

double MIN = 10;

double MAX = 20;

double num = 15;

1.    while (num < MAX)                                15

     {                                                16

        System.out.println (num);                     17

        num = num + 1;                                18

     }                                                19

2.    while (num < MAX)                                16

     {                                                17

        num = num + 1;                                18

        System.out.println (num);                     19

     }                                                20

3.    while (num < MAX)                                15

     {                                                14

        System.out.println (num);                     13

        num = num - 1;                             infinitely

     }

4.    while (num > MIN)                                15

     {                                                14

        System.out.println (num);                     13

        num = num - 1;                                12

     }                                                11

5.    while (num < MAX)                                15

     {                                                17

        System.out.println (num);                     19

        num = num + 2;

     }