Would that be?
double salario = 1500;
double desafio = 0;
for(double mes=1; mes<=12; mes++){
desafio += (salario * mes)/100;
System.out.println("Valor do Desafio:" + desafio);
}
This will add up the previous values to the current ones. See working on ideone: https://ideone.com/cxw87K
If you want to continue displaying the values of each month, just create a temporary variable within the loop:
double salario = 1500;
double desafio = 0;
for(double mes=1; mes<=12; mes++){
double mesAtual = (salario * mes)/100;
desafio += mesAtual;
System.out.println("Valor do Mes Atual:" + mesAtual);
}
System.out.println("Valor do desafio:" + desafio);
The exit will be:
Valor do Mes Atual:15.0
Valor do Mes Atual:30.0
Valor do Mes Atual:45.0
Valor do Mes Atual:60.0
Valor do Mes Atual:75.0
Valor do Mes Atual:90.0
Valor do Mes Atual:105.0
Valor do Mes Atual:120.0
Valor do Mes Atual:135.0
Valor do Mes Atual:150.0
Valor do Mes Atual:165.0
Valor do Mes Atual:180.0
Valor do desafio:1170.0
See it working on ideone: https://ideone.com/N1IKrg
Perfect.. I can use... but after generating all the results, how do I add up everything that generated?
– Maurício Maciel