Reputation: 1
thank you for read my question. I don´t have any problem with the compiler, and when I run the program the case 1 works well but the case 2 do not work, When I try to use it the program go back to the main menu. than you for your help.
public static void main(String[] args) {
int opcion=0;
double[][] m;
do{
m=new double[0][0];
opcion=Integer.parseInt(JOptionPane.showInputDialog(null,"El programa permite:\n1.Ingresar Inventario\n2.Calcular Inventario\n3.Salir"));
switch(opcion){
case 1:
m=Metodos.LLenarMatriz();
Metodos.Imprimir(m);
break;
case 2:
double[][] r=Metodos.CalcularInventario(m);
Metodos.Imprimir(r);
break;
}
}
while(opcion!=3);
}
}
Here are two methods:
public static double[][] CalcularInventario (double[][] x){
double fac,n=0;
int filx;
filx=x.length;
double [][] c=new double[filx][3];
for(int i=0;i<x.length;i++){
for(int j=0;j<x[i].length;j++){
c[i][j]=x[i][j];
}
}
for(int i=0; i<c.length;i++)
{
fac=x[i][0];
n=fac*c[i][1];
c[i][2]=n;
}
return c;
}
and
public static void Imprimir(double[][] m){
for(int i=0;i<m.length;i++){
System.out.print("\n");
for(int j=0;j<m[i].length;j++){
System.out.print(m[i][j]+"|");
}
}
}
}
Upvotes: 0
Views: 54
Reputation: 533820
This is where using a debugger would help debug your code but.
m=new double[0][0];
so the matrix is empty.
int filx;
filx=x.length;
double [][] c=new double[filx][3];
and x.length
is 0 so c
is empty.
for(int i=0;i<m.length;i++){
System.out.print("\n");
but m.length
is still 0 so it doesn't print anything.
I suggest you step through your code in your debugger to understand at what point it isn't doing what you expected. I also suggest you use the formatter in your IDe to make your code easier to read.
Upvotes: 2