In: Computer Science
1. I need a java program that prints the following rows of arrays, like shown
[3,5,6
7, 61, 71,
9, 99, 999,
4, 1, 0]
2. I also need a program that prints the sum of all the arrays
3. and a third program that only prints the elements from row one.
Thanks!
public class Main
{
public static void main(String[] args) {
int sum;
int arr[][]={
{3,5,6},{7,61,71},{9,99,999},{4,1,0}};//declare arr of size 4 rows
3 columns
// to print array contents row wise
for(int i=0;i<4;i++)
{
for(int j=0;j<3;j++)
System.out.print(arr[i][j]+" ");
System.out.print("\n");
}
//to print sum row wise
for(int i=0;i<4;i++)
{
sum=0;
for(int j=0;j<3;j++)
sum=sum+arr[i][j];
System.out.println("Sum of row
"+(i+1) +" is :"+sum);
}
//print elements of row 1
System.out.println("\nThe elements of Row1 are
:");
for(int i=0, j=0;j<3;j++)
System.out.print(arr[i][j]+" ");
}//end main()
}//end class