pTutorial

New way to learn Programming

Java two dimensional array maximum

Java program for finding the maximum integer in the following two dimensional array with the help of loop. You can make this java program user define by using previous example.

Java two dimensional array max

public class MaximumInTwoDiementionalArray {
public static void main(String... z){
    int b=max(new int[][] {{10,1,330},{50,30000,1000},{70,5,20}});
    System.out.println("Maximum number in this array="+b);
}

static int max(int d[][])
{
    int c=d[0][0];
    for(int i=0;i<d.length;i++){
        for(int j=1;j<d.length;j++){
            if(c<d[i][j]){
                c=d[i][j];
            }
        }
    }
    return c;
}
}


Output

Maximum number in this array=30000

See Also


QUOTES OF THE DAY

Eat to live, and not live for eat.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER