total de gastos mensuales
Publicado por Alexs (10 intervenciones) el 07/04/2021 16:40:44

Valora esta pregunta


-1
public class MatrizGastosBasicos {
public static final String[] meses = {
"Enero", "Febrero", "Marzo",
"Abril", "Mayo", "Junio",
"Julio", "Agosto", "Septiembre",
"Octubre", "Noviembre", "Diciembre"
};
public static double[][] getMatrizGastos() {
return new double[][]{
{11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 10.0, 11.0, 12.0},
{11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 10.0, 11.0, 12.0}
};
}
public static void main(String[] args) {
double[][] gastos = getMatrizGastos();
int mes = 0;
System.out.println("Gastos mensuales: ");
for (int i = 0; i < 12; i++) {
System.out.println(meses[i] + ": " + (gastos[0][i] + gastos[1][i]));
if (gastos[0][i] + gastos[1][i] > gastos[0][mes] + gastos[1][mes]) {
mes = i;
}
}
System.out.println("El mes con mayor gastos fue: " + meses[mes] + " con " + (gastos[0][mes] + gastos[1][mes]) + " gastado");
}
}