Java MULTIPLE CHOICE. Choose the one alternative that best completes the stateme
ID: 3802994 • Letter: J
Question
Java
MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question
15) 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);
15)
A) 6 B) 8 C) 7 D) 5
16) Do the following two statements in (I) and (II) result in the same value in sum?
(I): for (int i= 0; i<10; ++i) { sum += i; }
(II): for (int i= 0; i<10; i++) { sum += i; }
16)
A) Yes B) No
17) How many times will the following code print "Welcome to Java"?
int count= 0; while (count++ < 10) { System.out.println("Welcome to Java"); }
17)
A) 9 B) 10 C) 8 D) 11 E) 0
18) To declare an int variable number with initial value 2, you write 18) A) int number= 2.0; B) int number= 2L; C) int number= 2l; D) int number= 2;
3
19) What is y displayed?
public class Test { public static void main(String[ ] args) { int x= 1; int y= x+ x++; System.out.println("y is "+ y); } }
19)
A) y is 3. B) y is 4. C) y is 2. D) y is 1.
Explanation / Answer
15) sum after the following loop terminates----->
int sum = 0; int item= 0; do { item++; sum += item; if (sum > 4) break; } while (item < 5);
Answer :-
A) 6
16) Do the following two statements in (I) and (II) result in the same value in sum?
(I): for (int i= 0; i<10; ++i) { sum += i; }
(II): for (int i= 0; i<10; i++) { sum += i; }
Answer :-
A) Yes
Hint :- first loop will give 45 and second will also give 45
17) How many times will the following code print "Welcome to Java"?
int count= 0; while (count++ < 10) { System.out.println("Welcome to Java"); }
Answer :-
B) 10
18) To declare an int variable number with initial value 2, you write
Answer
D) int number= 2;
19) What is y displayed?
public class Test { public static void main(String[ ] args) { int x= 1; int y= x+ x++; System.out.println("y is "+ y); } }
Answer :-
C) y is 2.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.