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