Advertisements
Advertisements
Question
A Departmental Shop has 5 stores and 6 departments. The monthly sale of the department is kept in the Double Dimensional Array (DDA) as m[5][6].
The Manager of the shop wants to know the total monthly sale of each store and each department at any time. Write a program to perform the given task.
Hint: Number of stores as rows and Number of departments as columns.
Answer in Brief
Solution
import java.util.*;
class AQ16
{public static void main(String args[])
{Scanner ob = new Scanner(System.in);
int i, j, rowsum = 0, colsum = 0;
int m[][] = new int[5][6];
System.out.println("Enter the numbers of the matrix");
for (i = 0; i < 5; i++)
{for (j = 0; j < 6; j++)
m[i][j] = ob.nextlnt();
}
// ROW WISE (STORE WISE) TOTAL
System.out.println("The numbers of the matrix are");
for (i = 0; i < 5; i++)
{rowsum = 0;
for (j = 0; j < 6; j++)
{System.out.print(m[i][j] + "\");
rowsum += m[i][j];
}
System.out.print("Sales in Store" + (i + 1) + " : " + rowsum);
System.out.println();
}
// COLUMN WISE (DEPT WISE) TOTAL
for (i = 0; i < 6; i++)
{colsum = 0;
for(j = 0; j < 5; j++)
colsum += m[j][i];
System.out.printIn("\tSales in Dept" + (i + 1) + " : " + colsum);
}
}}
shaalaa.com
Is there an error in this question or solution?
Chapter 3: Arrays (Single Dimensional and Double Dimensional) - EXERCISES [Page 243]