Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Test 11) How many times will the following code print \"Welcome to Java\"?

ID: 3819902 • Letter: J

Question

Java Test

11) How many times will the following code print "Welcome to Java"? int count = 0; do { System.out.println("Welcome to Java"); } while (count++ < 10);

11) A) 11 B) 0 C) 8 D) 9 E) 10

12) What is sum after the following loop terminates? int sum = 0; int item = 0; do { item++; sum += item; if (sum > 4) break; } while (item < 5);

12) A) 5 B) 7 C) 6 D) 8

13) What is i after the following for loop? int y = 0; for (int i = 0; i<10; ++i) { y += i; }

13) A) 9 B) 11 C) 10 D) undefined

14) How many times will the following code print "Welcome to Java"? int count = 0; while (count < 10) { System.out.println("Welcome to Java"); count++; }

14) A) 11 B) 8 C) 0 D) 10 E) 9

15) How many times will the following code print "Welcome to Java"? int count = 0; while (count++ < 10) { System.out.println("Welcome to Java"); }

15) A) 0 B) 10 C) 9 D) 11 E) 8 3

Explanation / Answer

(11)
   (a) Initially variable count is initialized to 0.
   (b)   do-while loop iterates i from 0 to 11. When i value is 11 the loop gets stopped.
   (c) So the given code prints 11 times.

   Hence correct option is (A)
  
______________________________________________________________________________________________________

(12)
   (a)   Initially variables sum and item are initialized to 0
  
   sum = 0, item = 0 => item = 1, sum = 1
   sum = 1, item = 1 => item = 2, sum = 3
   sum = 3, item = 2 => item = 3, sum = 6
  
   When value of sum is 6, break statement gets executed and iteration gets stopped.
  
   Hence correct option is (C)
  
______________________________________________________________________________________________________

(13)
   (a)   Initially i is set to 0.
   (b)   for loop gets iterated from 0 to 10. When the value of i is 10, condition i<10 evaluates to false and the loop iteration gets stopped.
   (c) Value of i after executing the loop is 11.
  
   Hence correct option is (B)
  
______________________________________________________________________________________________________

(14)
   (a) Initially variable count is initialized to 0.
   (b)   while loop iterates i from 0 to 10. When i value is 10 the loop gets stopped.
   (c) So the given code prints "Welcome to Java" statement 10 times.

   Hence correct option is (D)
______________________________________________________________________________________________________

(15)
   (a) Initially variable count is initialized to 0.
   (b)   while loop iterates i from 1 to 11. When i value is 11 the loop gets stopped.
   (c) So the given code prints "Welcome to Java" statement 10 times.

   Hence correct option is (B)
   

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote