Skip to main content

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.

 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.


import java.util.Scanner;
class Department{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int deptshop[][] = new int[5][6]; //5 stores(rows) 6 deparments(columns)
int sales[] = new int[5]; //total sales data for 5 stores
for(int i=0;i<5;i++){ //row
System.out.println("Enter data for store:"+(i+1));
int sum=0;
for(int j=0;j<6;j++){ //column
System.out.println("Enter sales amount into department "+(j+1));
deptshop[i][j]=sc.nextInt();
sum=sum+deptshop[i][j];
}
sales[i]=sum; //store the total sales amount for each store
}
System.out.println("Enter the store number (1 to 5)");
int stn = sc.nextInt();  //store number
System.out.println("Total sale of store number:"+stn+" is "+sales[stn-1]);
System.out.println("Enter department number (1 to 6)");
int dtn = sc.nextInt(); //store the department number
System.out.println("Sales of department is: "+deptshop[stn-1][dtn-1]);
}
}

Popular posts from this blog