Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

. What does the following segment of code print out? IN JAVA int s = 1; int n; f

ID: 3592988 • Letter: #

Question

 . What does the following segment of code print out?  IN JAVA       int s = 1;      int n;      for(n = 1; n <= 5; n++)      {         s += n;         n++;      }      System.out.println("s = " + s);          System.out.print("n = " + n);                      2. Convert the following "for" loop to a "while" loop:       int x;      for(x = 10; x >= 0; x--)      {         System.out.println( x + " seconds to go.");      }    3. What is printed by the following segment of Java code?       int j = 1;      while(j < 3);      {          System.out.println(j);          j++;      }      System.out.println("Final j = " + j);                                      4. What does the following segment of code print out?     int i = 4;     do     {                 System.out.println("iteration " + i);                 i--;     } while(i > 4);                            5. What will be the output of the nested loop below?      int height = 3, width = 4;              for(int i = 1; i <= height; i++)     {        for(int j = 1; j <= width; j++)        {           System.out.print("*");        }        System.out.println();     }          

Explanation / Answer

Question 1

Answer:

s = 10
n = 7

Question 2

Answer:

int x = 10;

while(x >= 0)

{

System.out.println( x + " seconds to go.");

x--;

}

Question 3

Answer:

1
2
Final j = 3

Question 4

Answer:

iteration 4

Question 5

Answer:

****
****
****