‹ Back to the paper
Choose the correct option.
What will be the output of the method single() when the value of x[] = {10,2,9,-6,5,6}?
- (i)120
- (ii)45
- (iii)720
- (iv)18
Show the code
void single(int x[])
{
int w = 1;
for(int y = 0; y < x.length; y++)
{
if(x[y] % 2 == 0 && x[y] > 0)
w = w * x[y];
}
System.out.print(w);
}Answer
Answer
AICorrect option: (i)
Answer: (i) 120
Only positive even elements 10, 2, 6 are multiplied: 10 x 2 x 6 = 120.
From ISC 2022 Computer Science - Specimen paper (Semester 1), Paper 1, question 29(a).