Computer Applications
Write a code segment that finds the largest integer in this two-dimensional array.
int data[][] = new int[5][5];
Java Arrays
7 Likes
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);
Answered By
5 Likes
Related Questions
Write a code segment to compute the sum of all positive real numbers stored in the following array.
double numb[] = new double[50];
What happens in Java if you try to access an element that is outside the bounds of the array?
A student wrote the following code segment, intending to print 11 22 33 44:
int arr[] = {11, 22, 33, 44}; for (int i = 1; i <= 4; i++) System.out.println(arr[i]);
However, the program crashed with a run-time error. Can you explain the reason for this?
Given the following declarations:
final int SIZE = 20; char[] name = new char[SIZE];
i. Write an assignment statement that stores 'D' into the first element of the array name.
ii. Write an output statement that prints the value of the tenth element of the array name.
iii. Write a for statement that fills the array name with spaces.