ASU CSE 110 FINAL JAVA FALL WINTER 2022 FINAL PAPER 2026 COMPLETE SOLUTIONS AND CORRECT AN, Exams of Java Programming

ASU CSE 110 FINAL JAVA FALL WINTER 2022 FINAL PAPER 2026 COMPLETE SOLUTIONS AND CORRECT ANSWERS GRADED A+

Typology: Exams

2025/2026

Available from 01/28/2026

HighMark_Prep
HighMark_Prep 🇺🇸

5

(3)

27K documents

1 / 144

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ASU CSE 110 FINAL JAVA FALL WINTER
2022 FINAL PAPER 2026 COMPLETE
SOLUTIONS AND CORRECT ANSWERS
GRADED A+
22) What will be the output of the following code snippet?
boolean token = false;
while (token)
{
System.out.println("Hello");
}
a) "Hello" will be displayed infinite times.
b) No output because of compilation error.
c) No output after successful compilation.
d) "Hello" will be displayed only once. Answer: Answer: c) No output
after successful compilation.
23) What will be the output of the following code snippet?
boolean token = false;
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download ASU CSE 110 FINAL JAVA FALL WINTER 2022 FINAL PAPER 2026 COMPLETE SOLUTIONS AND CORRECT AN and more Exams Java Programming in PDF only on Docsity!

ASU CSE 110 FINAL JAVA FALL WINTER

2022 FINAL PAPER 2026 COMPLETE

SOLUTIONS AND CORRECT ANSWERS

GRADED A+

⩥ 22) What will be the output of the following code snippet? boolean token = false; while (token) { System.out.println("Hello"); } a) "Hello" will be displayed infinite times. b) No output because of compilation error. c) No output after successful compilation. d) "Hello" will be displayed only once. Answer: Answer: c) No output after successful compilation. ⩥ 23) What will be the output of the following code snippet? boolean token = false;

do { System.out.println("Hello"); } while (token); a) "Hello" will be displayed infinite times. b) No output because of compilation error. c) No output after successful compilation. d) "Hello" will be displayed only once.. Answer: Answer: d) "Hello" will be displayed only once. ⩥ 24) 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; } a) No output because of compilation error.

⩥ 26) How many times does the code snippet below display "Hello"? int i = 0; while (i != 15) { System.out.println("Hello"); i++; } a) Infinite times b) 14 times c) 15 times d) 16 times. Answer: Answer: c) 15 times ⩥ 27) 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; } } a) 9 times b) 8 times c) 5 times d) 1 time. Answer: Answer: c) 5 times ⩥ 28) 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");

i = i + 1; } while (x < 2.5); System.out.print(i + " "); a) 1 b) 2 c) 3 d) 4. Answer: Answer: c) 3 ⩥ 30) What will be the range of the random numbers generated by the following code snippet? int r1 = (int) (Math.random() * 50) + 1; a) Between 1 and 49 b) Between 0 and 50 c) Between 0 and 49 d) Between 1 and 50. Answer: Answer: d) Between 1 and 50 ⩥ 31) 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?

a) (int) (Math.random() * 6 + 1) b) (int) (Math.random() * 12 + 1) c) (int) (Math.random() * 6 + 1) + (int) (Math.random() * 6 + 1) d) (int) (Math.random() * 12 - 2). Answer: Answer: c) (int) (Math.random() * 6 + 1) + (int) (Math.random() * 6 + 1) ⩥ 32) Given the following code snippet, what should we change to have 26 alphabet characters in the string str? String str = ""; for (char c = 'A'; c < 'Z'; c++) { str = str + c; } a) int c = 'A' b) str = c + str; c) c <= 'Z' d) Must change to use a do loop. Answer: Answer: c) c <= 'Z ⩥ 33) What is the output of the code snippet given below?

System.out.print(s.substring(i, i + 1)); } } while (i < 5); a) No output b) No output (infinite loop) c) abcde d) bcde. Answer: Answer: b) No output (infinite loop) ⩥ 35) What is the output of the code snippet given below? String s = "12345"; int i = 1; while (i < 5) { System.out.print(s.substring(i, i + 1)); i++; } a) No output b) 1234

c) 12345 d) 2345. Answer: Answer: d) 2345 ⩥ 36) What is the output of the code snippet given below? String s = "12345"; int i = 1; do { if (i > 1) { System.out.print(s.substring(i, i + 1)); } } while (i < 5); a) No output b) No output (infinite loop) c) 12345 d) 2345. Answer: Answer: b) No output (infinite loop)

int i = 0; int j = 0; while (i < 125) { i = i + 2; j++; } System.out.println(j); a) 0 b) 62 c) 63 d) The code fragment displays no output because it does not compile.. Answer: Answer: c) 63 ⩥ 40) What is the output of the following code snippet? int i = 1; while (i < 20) { System.out.print(i + " "); i = i + 2;

if (i == 15) { i = 19; } } a) 1 3 5 7 9 11 13 15 17 19 b) 1 3 5 7 9 11 13 19 c) 1 3 5 7 9 11 13 15 17 d) 1 3 5 7 9 11 13 17 19. Answer: Answer: b) 1 3 5 7 9 11 13 19 ⩥ 41) What are the values of i and j after the following code snippet is run? int i = 10; int j = 20; int count = 0; while (count < 5) { i = i + i; i = i + 1; j = j - 1;

b) The value of sum is 105 c) The value of sum is 120 d) The value of sum is 136. Answer: Answer: c) The value of sum is 120 ⩥ 43) 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++; } a) 3 2 *** b) 9 8 7 6 5 4 3 2 *** c) 8 7 6 5 4 3 2 *** d) 2 ***. Answer: Answer: b) 9 8 7 6 5 4 3 2 ***

⩥ 44) Which of the following is considered a loop with a bound that could be problematic? a) for (i = 1; i != n; i++) b) for (years = n; years < 0; years--) c) for (i = 1; i <= n; i++) d) for (int i = 1; i <= 10; i++). Answer: Answer: a) for (i = 1; i != n; i++) ⩥ 45) In the __________ loop header, you can include multiple update expressions, separated by commas, but it is not recommended. a) do b) while c) for d) do. Answer: Answer: b) while ⩥ 46) What values does counter variable i assume when this loop executes? for (int i = 20; i >= 2; i = i - 6) { System.out.print(i + ",");

a) stop; b) done = 1; c) exit; d) done = true;. Answer: Answer: d) done = true; ⩥ 48) What is the output of the code snippet given below? String s = "abcdefghijkl"; int i = 1; do { if (i > 2) { System.out.print(s.substring (1, i)); } i++; } while (i < 5);

a) abcd b) bcde c) bcbcd d) cdef. Answer: Answer: c) bcbcd ⩥ 49) What is the output of this code snippet if the user enters the numbers 1 2 3 4 - 1 5? double total = 0; boolean hasValidNumber = true; Scanner in = new Scanner(System.in); while (in.hasNextDouble() && hasValidNumber) { double input = in.nextDouble(); if (input < 0) { hasValidNumber = false; } else { total = total + input; }