1.

Question 7Write a program in Java to accept 16 values (of int type) in a double dimension arrayart[][] of order 4 x 4 and perform the following:(i) calculate and print the sum of the elements of the first row.(ü) calculate and print the sum of the elements of the last column.(iii) print the array in matrix form.For example if the values in the array entered are:3 9 5 68 4 2 09 4 12 1620 1 25 7Then the output will be:Sum of the first row: 23Sum of last column : 29Array in matrix form3 9 5 68 4 2 09 4 12 1620 1 25 7​

Answer»

Answer:

import java.util.*;

class DD

{

public static void main (String args[])

{

Scanner in= new Scanner (System.in);

int arr [][]=new int[4][4];

int sumrow=0,sumcolumn=0;

for( int i= 0;i<4;i++)

{

for( int j= 0;j<4;j++)

{

if(i==0)

{

sumrow=sumrow+arr[i][j];

}

if(j==3)

{

sumcolumn=sumcolumn+arr[i][j];

}

}

}

for( int i= 0;i<4;i++)

{

for( int j= 0;j<4;j++)

{

System.out.print(arr[i][j]);

}

System.out.println();

}

System.out.println(" SUM of first ROW" +

sumrow);

System.out.println("Sum of last column "

sumcolumn);

}

}

//hope it helped



Discussion

No Comment Found