ICSE Class 10 Computer Applications Question 11 of 59

Arrays — Question 13

Back to all questions
13
Question

Question 13

Write a code segment that finds the largest integer in this two-dimensional array.

int data[][] = new int[5][5];
Answer
int l = data[0][0];
for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) {
        if (data[i][j] > l) {
            l = data[i][j];
        }
    }
}
System.out.println("Largest Element = " + l);