pTutorial

New way to learn Programming

Java array example for interview questions

1 2 3
4 5 6
7 8 9

Java array highest element in upper triangular matrix

class HighestElementInUpperHalf{
public static void main(String... z){
	int b=max(new int[][] {{1,2,3},{4000,50,6},{7,8,9}});
	System.out.println("Highest 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=(i+1)-1;j<d[i].length;j++){
			if(c<d[i][j]){
				c=d[i][j];
			}
		}
	}
	return c;
}
}

Output

Highest number in this array=50

See Also


QUOTES OF THE DAY

Beauty's tears are lovelies than her smiles.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER