-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
47 lines (42 loc) · 1.29 KB
/
Main.java
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
/*
* Dado o valor de faturamento mensal de uma distribuidora, detalhado por estado:
*
* SP – R$67.836,43
* RJ – R$36.678,66
* MG – R$29.229,88
* ES – R$27.165,48
* Outros – R$19.849,53
*
* Escreva um programa na linguagem que desejar onde calcule o percentual de representação que cada
* estado teve dentro do valor total mensal da distribuidora.
*/
package application;
public class Main {
public static void main(String[] args) {
String state[] = new String[] {
"SP",
"RJ",
"MG",
"ES",
"Outros"
};
double monthlyBillingState[] = new double[] {
67836.43d,
36678.66d,
29229.88d,
27165.48d,
19849.53d
};
double totalBilling = 0;
double percentage;
for (int i = 0; i < state.length; i++) {
totalBilling += monthlyBillingState[i];
}
System.out.println("Faturamento total: R$ " + totalBilling);
System.out.println();
for (int i = 0; i < state.length; i++) {
percentage = (monthlyBillingState[i] / totalBilling) * 100;
System.out.printf("Percentual de %s: %.2f%%\n", state[i], percentage);
}
}
}