1z0-819 Exam QuestionsBrowse all questions from this exam

1z0-819 Exam - Question 46


What is the result?

Show Answer
Correct Answer: AB

The given code initializes an array of prime numbers and a string to store the result. The while loop runs while 'i' is less than the length of the array. The condition inside the loop checks if 'i' is equal to 3 and breaks if true. The variable 'i' is incremented before appending the value of 'primes[i]' to the result string. The loop starts with 'i' equal to 0, increments it and appends the next prime number each time. So, primes[1]=3 and primes[2]=5 are appended, the loop breaks when 'i' becomes 3. Thus, the correct result is '35'.

Discussion

5 comments
Sign in to comment
TADIEWAOption: A
Dec 25, 2022

A is correct

StavokOption: A
Jun 7, 2023

A is correct

tmuralimanoharOption: A
Jun 28, 2023

Answer: A

d7bb0b2Option: A
Jan 7, 2024

private static int i ; private static int primes[] = {2,3,5,7}; private static String resulet = ""; public static void main(String[] args) { while (i < primes.length) { if( i == 3) { break; } i++; resulet += primes[i]; } System.out.println(resulet); } A: is correct only know what happend with i = 2 case, event before append increment so when is 2 increment i = 3 and array contain element 3, so append its ok. After that while is break for if condition

edwMr9Option: A
Jul 2, 2024

The line that contains i++ removes the option to print the first number, that is, it verifies that it prints 357, and "A" is the correct