java - Why the switch statement does not enter to the case 2? -


thank read question. don´t have problem compiler, , when run program case 1 works case 2 not work, when try use program go main menu. 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 2 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]+"|");          }      } } 

}

this using debugger debug code but.

m=new double[0][0]; 

so matrix empty.

int filx; filx=x.length; double [][] c=new double[filx][3]; 

and x.length 0 c empty.

for(int i=0;i<m.length;i++){     system.out.print("\n"); 

but m.length still 0 doesn't print anything.

i suggest step through code in debugger understand @ point isn't doing expected. suggest use formatter in ide make code easier read.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -