Repository navigation
Expand file tree
/
Copy pathHome1.java
More file actions
53 lines (47 loc) · 1.65 KB
/
Copy pathHome1.java
File metadata and controls
53 lines (47 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package Day16;
public class Home1 {
// walmart costco corrado's AVG
// apple 3 4 5 4
// milk 3 3 3 3
// meat 4 5 4 4.33
// bread 1 1 2 1.33
// TOTAL 11 13 14
// given table,
// part1. calculate sum of price in each market(walmart,costco,corrado's)
// expected output is:
// Total at Walmart is: ???
// Total at costco is: ???
// Total at corrado's is: ???
// part2. calculate average price of each item(apple, milk, meat, bread)
// expected output is:
// average price of apple is: ???
// average price of milk is: ???
// average price of meat is: ???
// average price of bread is: ???
public static void main(String[] args) {
int[][] prices = {
{1, 1, 1},
{1, 1, 1},
{1, 1, 1},
{1, 1, 1},
{10, 20, 40}
};
System.out.println("Average price of items");
for (int i = 0; i < prices.length; i++) {
int sum = 0;
for (int j = 0; j < prices[i].length; j++) {
sum += prices[i][j]; // sum = sum + prices[i][j];
}
double avg = (double) sum / prices[i].length;
System.out.println(i +". item avg: " + avg);
}
System.out.println("Sum price of markets");
for (int i = 0; i < prices[i].length; i++) {
int sum = 0;
for (int j = 0; j < prices.length; j++) {
sum += prices[j][i]; // sum = sum + prices[i][j];
}
System.out.println(i +". market sum: " + sum);
}
}
}