JAVA : What will be the output of the following Java code snippet?
SDET Automation Testing Interview Questions & Answers
We will be covering a wide range of topics including QA manual testing, automation testing, Selenium, Java, Jenkins, Cucumber, Maven, and various testing frameworks.
JAVA : What will be the output of the following Java code snippet?
int[] arr = {10, 20, 30, 40, 50};
for(int i=0; i(arr.length; i++) {
if(arr[i] == 30) {
continue;
}
System.out.print(arr[i] + " ");
}
Options:
A) 10 20 40 50
B) 10 20 30 40 50
C) 10 20 50
D) 30 40 50
Answer: Option A) 10 20 40 50
Explanation:
In the given code snippet, an integer array arr is initialized with five elements.
A for loop is used to iterate over each element of the array.
Inside the loop, an if condition checks if the current element is equal to 30.
If the condition is true, then the continue statement is executed, which skips the remaining code inside the loop for that iteration and jumps to the next iteration.
Therefore, when the loop encounters the element with value 30, it skips printing it and moves on to the next iteration. For all other elements, the print statement inside the loop is executed, which prints the element followed by a space.
As a result, the output of this code will be: 10 20 40 50. Therefore, the correct answer is A) 10 20 40 50.
Смотрите видео JAVA : What will be the output of the following Java code snippet? онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь SDET Automation Testing Interview Pro 05 Май 2023, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 741 раз и оно понравилось 26 людям.