Exam 6: Loops

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

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

(Multiple Choice)
4.8/5
(38)

How many times does the following code fragment display "Hi"? Int i = 10; While (i >= 0) { System.out.println("Hi"); I--; }

(Multiple Choice)
4.9/5
(41)

What will be printed by the statements below? Int a = 10; While (a > 5) { A = a - 2; System.out.print (a + " "); }

(Multiple Choice)
4.9/5
(46)

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.9/5
(41)

What is the data type of the number generated by the Random.nextDouble() method?

(Multiple Choice)
4.8/5
(24)

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.8/5
(28)

What is the output of the code snippet given below? String s = "abcde"; Int i = 1; While (i < 5) { System.out.print); I++; }

(Multiple Choice)
4.8/5
(38)

Which of the following for loops is illegal?

(Multiple Choice)
4.9/5
(36)

When hand tracing, drawing a line through the value stored in a variable means that

(Multiple Choice)
4.9/5
(42)

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

(Multiple Choice)
4.7/5
(39)

Which of the following loops will print the odd numbers between 0 and 20?

(Multiple Choice)
4.7/5
(40)

What is the output of the code below? for (int val = 0; val < 4; val ++) { Int sum = val; For (int num = 0; num < val; num++) { Sum = sum + num; } System.out.print (sum + " "); }

(Multiple Choice)
4.8/5
(34)

What does the method below return? Int findSomething (String str) { Int position = 0; While (position < str.length() && (str.charAt (position) != 'e')) { Position++; } Return position; }

(Multiple Choice)
4.7/5
(42)

Which of the following loops executes the statements inside the loop before checking the condition?

(Multiple Choice)
4.8/5
(40)

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 code snippets will generate a random number between 0 (inclusive) and 79 (inclusive)? (Assume Random generator = new Random();)

(Multiple Choice)
4.9/5
(38)

Which of the following is the correct code snippet for throwing a pair of dice to get a sum of the numbers on two dice between 2 and 12 with different probabilities? (Assume Random generator = new Random();)

(Multiple Choice)
4.8/5
(43)

Which of the following code snippets displays the output exactly 10 times?

(Multiple Choice)
4.8/5
(37)

What is the output of the code snippet given below? Int i = 0; While (i != 11) { System.out.print(" " + i); I = i + 2; }

(Multiple Choice)
4.8/5
(38)

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
(38)
Showing 81 - 100 of 128
close modal

Filters

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