2-D Array + Sum up Horizontally & Vertically


public class Matrix
{
public static void main(String[] args)
{
int[][] x = new int[8][8];
int[] y = new int[x.length];
int[] z = new int[x.length];

for(int i=0; i< x.length; i++)
{
for(int j=0; j < x[i].length; j++)
{
x[i][j]=(int)(Math.random()/Math.random());
}
}

System.out.println();
System.out.println("2-D Random Integer Array!");
int counter=0;

for(int i=0; i< x.length; i++)
{
for(int j=0; j < x[i].length; j++)
{
System.out.print(x[i][j]+" ");
y[i] +=x[i][j];
z[i] +=x[j][i];
}

System.out.println();
}

System.out.println();
System.out.println("Sum 2-D Random Integer Array Horizontally!");

for(int i=0; i<y.length; i++)
{
System.out.println(y[i]);
}

System.out.println();
System.out.println("Sum 2-D Random Integer Array Vertically!");
for(int i=0; i<z.length; i++)
{
System.out.println(z[i]);
}
}
}

Advertisement
  1. No trackbacks yet.

You must be logged in to post a comment.
Follow

Get every new post delivered to your Inbox.