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

× G the scope of a variable ox Qcsci Ch 5 Flashcards QEGR 125 Flashcards0xDlava

ID: 3701428 • Letter: #

Question

× G the scope of a variable ox Qcsci Ch 5 Flashcards QEGR 125 Flashcards0xDlava Chapter 5 ) × 1195143/quizzes/1694069/take Programming Output Questions For each of the given program segments, read the code and write the output in the space provided below each program. [Note: Do not execute these programs on a computer.] For the following questions, assume that the code segments are contained within the main method of a Java ap- plication. For programming output question 1-4 use the following code segment: 1 int startingvalue; 2 int terminatingvalue; 3 int stepValue; 5 for ( int í “ start ingvalue; i

Explanation / Answer

In first 3 lines of code we declared the variables.

if we place the code segment given in question 4 at the line 4,those variables will be assigned some value.

hence the variables will be initialized by the newly added code segment.

now the variables values are:

startingValue = 0;

terminatingValue = 5;

stepValue = 3;

while coming to the loop execution.....

for fisrt iteration check....

i contains the startingValue i.e. i=0;

i<terminatingValue that means 0<5 is true,hence loop runs...

this will print value of i i.e. 0

for second iteration check....

i will be incremented by the stepValue i.e. i=i+stepValue = 0+3 = 3;

now i contains value 3

i<terminatingValue that means 3<5 is true,hence loop runs...

this will print value of i i.e. 3

for third iteration check....

i will be incremented by the stepValue i.e. i=i+stepValue = 3+3 = 6;

now i contains value 3

i<terminatingValue that means 6<5 is false,hence loop ends...