Exam 4: Loops

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

What is the output of the following code snippet? Int i = 1; While (i <= 10) { System.out.println("Inside the while loop"); I = i + 10; }

(Multiple Choice)
4.9/5
(38)

What is the output of the following code snippet? Int i = 1; While (i < 10) { System.out.print(i + " "); I = i + 2; If (i == 5) { I = 9; } }

(Multiple Choice)
4.8/5
(31)

What is the first and last value of i to be displayed by the following code snippet? Int n = 20; For (int i = 0; i <= n; i++) { For (int j = 0; j <= i; j++) { System.out.println("" + i); } }

(Multiple Choice)
4.8/5
(46)

Which for loop prints data across each row in the following code snippet? Int i; Int j; For (i = 1; i <= 3; i++) { For (j = 1; j <= 3; j++) { System.out.print("X"); } System.out.println(""); }

(Multiple Choice)
4.9/5
(35)

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

(Multiple Choice)
4.8/5
(36)

How many times does the following loop execute? Int i = 0; Boolean found = false; While (i < 100 && !found) { i++; System.out.print(i + " "); int j = i * i; if ((i * i * i) % j == j) { found = true; } }

(Multiple Choice)
4.9/5
(41)

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

(Multiple Choice)
4.8/5
(47)

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

(Multiple Choice)
4.8/5
(34)

What is the output of this loop? int i = 0; boolean found; while (i < 20 && !found) { int sum = i * 2 + i * 3; System.out.print(sum + " "); if (sum > 50) { found = true; } i++; }

(Multiple Choice)
4.9/5
(38)

Which of the loop(s) test the condition after the loop body executes? I. for loop II. while loop III. do loop

(Multiple Choice)
4.9/5
(49)

What is the output of this code snippet? String str = "ABCabc"; Char ch; Int i = 0; While (i < str.length()) { Ch = str.charAt(i); If (Character.isLowerCase(ch)) { System.out.print(i + " "); } Else { I++; } }

(Multiple Choice)
4.7/5
(39)

How many times will the following loop run? Int i = 0; While (i < 10) { System.out.println(i); I++; }

(Multiple Choice)
4.8/5
(33)

How many times does the following loop execute? For (double d = 1; d != 10; d++) { D = d / 3; System.out.print(d + " "); }

(Multiple Choice)
4.8/5
(42)

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
(40)

What does the following code snippet print? int a = 120; int b = 90; int n1 = Math.abs(a); int n2 = Math.abs(b); int result = 1; for (int k = 1; k <= n1 && k <= n2; k++) { if (n1 % k == 0 && n2 % k == 0) { result = k; } } System.out.println(result);

(Multiple Choice)
4.9/5
(35)

Which loop does not check a condition at the beginning of the loop? I. The do loop II. The while loop III. The for loop

(Multiple Choice)
4.7/5
(30)

How many times does the following loop run? Int i = 0; Int j = 1; Do { System.out.println("" + i + ";" + j); I++; If (i % 2 == 0) { J--; } } While (j >= 1);

(Multiple Choice)
4.9/5
(39)

Which of the following loop(s) should be used when you need to ask a user to enter one data item and repeat the prompt if the data is invalid? I. for loop II. while loop III. do loop

(Multiple Choice)
4.8/5
(40)

What will be the output of the following code snippet? Boolean token1 = true; While (token1) { For (int i = 0; i < 10; i++) { System.out.println("Hello"); } Token1 = false; }

(Multiple Choice)
4.8/5
(30)

What does the following code do? Int sum = 0; Final int count = 1000; For (int i = 1; i <= count; i++) { Sum = sum + (int) (Math.random() * 101); } System.out.println(sum / count);

(Multiple Choice)
4.8/5
(37)
Showing 81 - 100 of 100
close modal

Filters

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