Exam 6: Loops

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

Is the code snippet written below legal? String s = "1234"; For (int i = 0; i <= 5; i++) { System.out.print); }

(Multiple Choice)
4.9/5
(25)

Assume the following variable has been declared and given a value as shown: Random rand = new Random(); Which of the following will generate a random integer in the range - 20 to 20, inclusive, where each value has an equal chance of being generated?

(Multiple Choice)
5.0/5
(39)

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

What is the output of the code snippet given below? Int i; Int j = 0; For (i = 0; i < 5; i++) { If (i % 2 == 0) { I = i + 2; J++; } Else { I++; J = j + 2; } J++; } System.out.println("i=" + i + ", j=" + j);

(Multiple Choice)
4.8/5
(46)

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

How many times does the following loop execute? double d; Random generator = new Random(); Double x = generator.nextDouble() * 100; Do { D = Math.sqrt(x) * Math.sqrt(x) - x; System.out.println(d); X = generator.nextDouble() * 10001; } While (d != 0);

(Multiple Choice)
4.8/5
(26)

Suppose that the chance to hit the jackpot in a lottery is one in one million. Which of the expressions simulates that random number? (Assume Random generator = new Random();)

(Multiple Choice)
4.7/5
(38)

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

What will be printed by the statements below? for (int ctr = 0; ctr < 10; ctr++) { System.out.print (ctr + " "); }

(Multiple Choice)
4.8/5
(41)

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

(Multiple Choice)
4.7/5
(42)

Which of the following loop(s) could possibly not enter the loop body at all? I. for loop II. while loop III. do loop

(Multiple Choice)
4.8/5
(37)

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);

(Multiple Choice)
4.8/5
(46)

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

What will be the output of the following code snippet? boolean token = false; Do { System.out.println("Hello"); } While (token);

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

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

How many times does the following loop execute? Int upperCaseLetters = 0; String str = "abcdEfghI"; Boolean found = false; For (int i = 0; i < str.length() && !found; i++) { Char ch = str.charAt(i); If (Character.isUpperCase(ch)) { Found = true; } }

(Multiple Choice)
4.9/5
(36)

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

(Multiple Choice)
4.9/5
(35)

Storyboards are a helpful part of the design process because the storyboard develops

(Multiple Choice)
4.8/5
(34)

How many times does the code snippet below display "Hello"? Int i = 0; While (i != 15) { System.out.println("Hello"); I++; }

(Multiple Choice)
4.8/5
(33)
Showing 21 - 40 of 128
close modal

Filters

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