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

Question 1 (0.5 points) Which expression is equivalent to if ( ! ( grade == sent

ID: 3854861 • Letter: Q

Question

Question 1 (0.5 points)

Which expression is equivalent to if ( ! ( grade == sentinelValue ) )?

Question 1 options:

Question 2 (1 point)

Analyze the following code.
int x = 1;
while (0 < x) && (x < 100)
System.out.println(x++);

Question 2 options:

What is the value in count after the following loop is executed?
int count = 0;
do {
System.out.println("Welcome to Java");
} while (count++ < 9);
System.out.println(count);

Question 3 options:

What balance after the following code is executed?
int balance = 10;
while (balance >= 1) {
if (balance < 9) continue;
balance = balance - 9;
}

Question 6 options:

Question 7 (1 point)

Which of the following statements about a dowhile repetition statement is true?

What is y after the following for loop statement is executed?
int y = 0;
for (int i = 0; i < 10; ++i) {
y += 1;
}

Question 7 options:

Question 9 options:

1) if ( grade !== sentinelValue ). 2) if ( grade != sentinelValue ). 3) ! if ( grade == sentinelValue ). 4) ! if ( grade !== sentinelValue ).

Explanation / Answer

1)Which expression is equivalent to if ( ! ( grade == sentinelValue ) )?

Ans) 2) if ( grade != sentinelValue ).

Reason: the code is looking for the grade whose value is not equal to sentinel value.

___________________

2) Analyze the following code.
int x = 1;
while (0 < x) && (x < 100)
System.out.println(x++);

Ans) The code does not compile because (0 < x) && (x < 100) is not enclosed in a pair of parentheses.

Reason: The condition must be in parenthesis. Here (0 < x) && (x < 100) is not inside parenthesis .So we will get compilation error.To solve this we have to do like this while ((0 < x) && (x < 100))

___________________

3) What is the value in count after the following loop is executed?
int count = 0;
do {
System.out.println("Welcome to Java");
} while (count++ < 9);
System.out.println(count);

Ans) 4) 10

Reason : here count++ is post incrementation.So each time after checking the condition the value of the count will be incremented by 1.

Like while(0<9) after that the count value incremented to 1

While(1<9) ----count=2

----

----

While(9<9) which is false .

So control will come out of the loop.after that the value of count will be incremented to 10.So finally the value of count=10

___________________

4) What balance after the following code is executed?
int balance = 10;
while (balance >= 1) {
if (balance < 9) continue;
balance = balance - 9;
}

Ans)

3)

The loop does not end

Reason: As the initial value of balance is 10. The while (balance >= 1) condition will be executed.

As the balance =10 this condition will not be executed.if (balance < 9)

So the next statement balance = balance - 9; will be executed.

So after this the balance value is 1.

Agian as the balance=1 this statement will get executed while (balance >= 1)

Now if (balance < 9) will get executed .

as we mentioned "continue" after this then again control wil go to the while (balance >= 1) as this is true

control enters into it and the loop executes for ever.

___________________

7) Which of the following statements about a dowhile repetition statement is true?

What is y after the following for loop statement is executed?
int y = 0;
for (int i = 0; i < 10; ++i) {
y += 1;
}

Ans) 3)10

Question 9)

3)

The body of a dowhile loop is always executed at least once.

________________Thank You

___________________

3)

The loop does not end