tgoop.com/java_codings/70
Last Update:
50. Double Matrix.
import java.util.*;
import java.text.DecimalFormat;
class DoubleMatrix
{
public static void main(String[] args)
{
double[][] a;
double[] s;
int row, col, k = 0, i, j;
double sum = 0.0;
DecimalFormat f = new DecimalFormat("##.####");
Scanner sc = new Scanner(System.in);
System.out.println("Enter size of row and column");
row = sc.nextInt();
col = sc.nextInt();
a = new double[row][col];
s = new double[col];
System.out.println("Enter elements of matrix");
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
a[i][j] = sc.nextDouble();
}
}
System.out.println("Double Matrix is : ");
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
System.out.print(" " + a[i][j]);
}
System.out.println();
}
//sum of the elements of double matrix
for (i = 0; i < col; i++)
{
for (j = 0; j < row; j++)
{
sum = sum + a[j][i];
}
s[k] = sum;
k++;
sum = 0;
}
for (i = 0; i < col; i++)
{
System.out.println("Sum of Column " + (i + 1) + " is : " + f.format(s[i]));
}
}
}
@java_codings
BY Advance Java 👨💻
Share with your friend now:
tgoop.com/java_codings/70