‹ Back to the paper
Choose the correct option.
What will be the output of the method dimen() when the value of n[][] = {{2,3,7},{1,5,9},{10,-3,8}}?
- (i)42
- (ii)33
- (iii)5
- (iv)37
Show the code
void dimen(int n[][])
{
int p = 0;
for (int i = 0; i < n.length; i++)
for(int j = 0; j < n[0].length; j++)
{
if(i == 0 || i == n.length - 1 || j == 0 || j == n[0].length - 1)
p = p + n[i][j];
}
System.out.print(p);
}Answer
Answer
AICorrect option: (iv)
Answer: (iv) 37
All elements except the centre 5 are boundary: 2+3+7+1+9+10-3+8 = 37.
From ISC 2022 Computer Science - Specimen paper (Semester 1), Paper 1, question 28(a).