Example:
1 0 0
2 3 0
4 5 6
public class arraydemotriangleAmax {
static void triangleAmax(int x[][])
{
int i,j,max=0;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{max=x[0][0];
if(i<=j)
{
if(x[i][j]>max)
{
max=x[i][j];
}
}
}
}
System.out.println("The Max Value in triangle A is:"+ max);
}
public static void main(String[] args)
{
triangleAmax(new int[][]{{1,2,3},{4,5,6},{7,8,9}});
}
}
No comments:
Post a Comment