Exam 4: Loops

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

What is the output of the following code snippet? Int counter = 1; For (double i = 0.01; i <= 1.0; i = i + 0.01) { Counter++; } System.out.println(counter);

Free
(Multiple Choice)
4.9/5
(46)
Correct Answer:
Verified

A

Insert a statement that will correctly terminate this loop when the end of input is reached. Boolean done = false; While (!done) { String input = in.next(); If (input.equalsIgnoreCase("Q")) { __________ } Else { Double x = Double.parseDouble(input); Data.add(x); } }

Free
(Multiple Choice)
4.8/5
(35)
Correct Answer:
Verified

D

When will the loop in the following code snippet stop? Java.util.Scanner in = new java.util.Scanner(System.in); Double sum = 0; Int count = 0; System.out.print("Enter values, Q to quit: "); Do { Double value = in.nextDouble(); Sum = sum + value; Count++; System.out.print("Enter values, Q to quit: "); } While (in.hasNextDouble() && count < 100); I. When the user enters an integer II. When the user enters an alphabetic character III. After the user enters 100 numbers

Free
(Multiple Choice)
4.8/5
(45)
Correct Answer:
Verified

D

Which code snippet produces the sum of the first n even numbers? (0 is not considered an even number.)

(Multiple Choice)
4.9/5
(31)

Choose the loop that is equivalent to this loop. Int n = 1; Double x = 0; Double s; Do { S = 1.0 / (n * n); X = x + s; N++; } While (s > 0.01);

(Multiple Choice)
4.8/5
(42)

What is the output of the code snippet given below? String s = "aeiou"; Int i = 0; Do { System.out.print); I++; If (i >= 3) { I = 5; } } While (i < 5);

(Multiple Choice)
4.8/5
(40)

What is the last output line of the code snippet given below? Int i = 0; While (i < 10) { Int num = 1; For (int j = i; j > 1; j--) { System.out.print(j + " "); Num = num * 2; } System.out.println("***"); I++; }

(Multiple Choice)
4.8/5
(46)

In the following code snippet, when does the execution of the program switch from the inner loop to the outer loop? Int i; Int j; For (i = 0; i <= 9; i++) { For (j = 1; j < 5; j++) { System.out.println("Hello"); } }

(Multiple Choice)
4.8/5
(36)

Which of the following loops executes exactly 10 times?

(Multiple Choice)
4.9/5
(41)

What is the output of this code snippet if the user enters the numbers 1 2 3 4 -1 5? Double total = 0; Boolean hasValidNumber = true; Scanner in = new Scanner(System.in); While (in.hasNextDouble() && hasValidNumber) { Double input = in.nextDouble(); If (input < 0) { HasValidNumber = false; } Else { Total = total + input; } } System.out.println(total);

(Multiple Choice)
4.9/5
(33)

What is the output of the following code fragment? Int i = 1; Int sum = 0; While (i <= 15) { Sum = sum + i; I++; } System.out.println("The value of sum is " + sum);

(Multiple Choice)
4.9/5
(33)

Which of the following for loops is illegal?

(Multiple Choice)
4.8/5
(41)

How many times is the text "Let's have fun with Java." printed when this code snippet is run? Int i = 0; Do { System.out.println("Let's have fun with Java."); I++; If (i % 2 == 0) { I = 10; } } While (i <= 10);

(Multiple Choice)
4.7/5
(38)

Which statement about storyboards is true?

(Multiple Choice)
4.9/5
(40)

In the __________ loop header, you can include multiple update expressions, separated by commas, but it is not recommended.

(Multiple Choice)
4.8/5
(42)

How many times does the loop execute in the following code fragment? Int i; For (i = 0; i < 50; i = i + 4) { System.out.println(i); }

(Multiple Choice)
4.9/5
(41)

Which of the following statements expresses why the following code is considered bad form? For (rate = 5; years-- > 0; System.out.println(balance)) ) . . I. Unrelated expressions in loop header II. Doesn't match expected for loop idiom III. Loop iteration is not clear

(Multiple Choice)
4.8/5
(39)

What is the result when the following code is run? Double x = 1; Double y = 1; Int i = 0; Do { Y = x / 2; X = x + y; I = i + 1; } While (x < 2.5); System.out.print(i + " ");

(Multiple Choice)
4.9/5
(47)

What values does counter variable i assume when this loop executes? For (int i = 20; i >= 2; i = i - 6) { System.out.print(i + ","); }

(Multiple Choice)
4.8/5
(25)

How many times does the following code snippet display "Loop Execution"? For (int i = 0; i < 10; i++); { System.out.println("Loop Execution"); }

(Multiple Choice)
4.8/5
(31)
Showing 1 - 20 of 100
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)