Question: 1.How many iterations will the following loop have? num1 = 10; num2 = 5; do { System.out.println( :) ); num2++; } while (num1

1.How many iterations will the following loop have?

num1 = 10;
num2 = 5;

do {
   System.out.println(" :) ");
   num2++;
} while (num1 < num2);
    A.     1
    B.     2
    C.     3
    D.     4
    E.     5
    F.     6
    G.     The condition is false, so the loop will not run.
    H.     Loop will run forever (an infinite loop).

2.I want to make some code repeat exactly 10 times.

I can use a for loop or a while loop, but NOT a do-while loop.
True
False

3. For a do-while loop, where is the modification expression placed?

___1___

do {
   ___2___
} while (___3___);

___4___
    A.     1 : before the loop
    B.     2 : in the loop body
    C.     3 : in the parentheses after the word "while"
    D.     4 : after the loop
    E.     None of the above.

4. For the following code, what is the variable scope of error?

String country = "Faroe Islands";
String error;
try {
   int numberOfPuffins = 500000;
   if (numberOfPuffins < 1000000) {
      double donation = 1000000.00;
      System.out.println("Donating $" + donation + " to save puffins!");
   }
}
catch (InputMismatchException ime) {
   error = "Oh no! Input is not acceptable.";
   System.out.println(error);
}
    A.     if statement
    B.     catch block
    C.     It can be used anywhere after it was declared.
    D.     It doesn't have a valid variable scope in this code.
    E.     try block

5. Which of the following is required for a loop?
    A.     modification expression
    B.     condition
    C.     initialization expression
    D.     exception
    E.     variable scope


Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The detailed answer for the above question is provided below 1 The loop in the question is a dowhile ... View full answer

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 Programming Questions!