how to write code of finding max. value in 2D Array in JAVA?
how to write code of finding max. value in 2D Array in JAVA?
in java
for example,
int[][] array={{8,4,5,1}, {2,3,4,5},{10,9,4,3}};
how to write the code for finding max. or min value in this 2d array?
and has to show in this value is in which row and column.
Tags: array, code, finding, java, max., value, write
Under Forum

1 Comment for how to write code of finding max. value in 2D Array in JAVA?
1. MIca G | February 15th, 2011 at 8:52 am
int[][] array={{8,4,5,1}, {2,3,4,99},{10,9,4,3}};
int min = Integer.MAX_VALUE;
int max = Integer.MIN_VALUE;
for (int a = 0; a < array.length; a++) {
for (int b = 0; b < array[a].length; b++) {
if(min > array[a][b]) {
min = array[a][b];
}
if(max < array[a][b]) {
max = array[a][b];
}
}
}
System.out.println(“Min = ” + min + ” Max = ” + max);
Leave a Comment for how to write code of finding max. value in 2D Array in JAVA?
You must be logged in to post a comment.
Trackback this post | Subscribe to the comments via RSS Feed