For conditional or array not working properly?

Hi everyone,

My problem is with java not with javascript, but I can´t select that topic.

I´m having a problem that I don´t see where it is. I´m giving with a for conditional values to an arraylist of two dimensions:

		ArrayList<ArrayList<String>> listaEmpresaA = new ArrayList<ArrayList<String>>();
				
		String [] paises = {"España", "USA"};
		
		int total_columnas = 1 + (paises.length*3);
		
		//Aquí creas las columnas
		 for(int i =0; i<= total_columnas; i++){
		            listaEmpresaA.add(new ArrayList<String>());
		        }
		 
		 //Aquí se definen las filas
		 
		 	
		 //Creo la cabecera
		 
		 listaEmpresaA.get(0).add("Juegos");
		 
		 for (int z=0 ; z<paises.length; z++) {
			 for (int j=1; j<total_columnas ; j=j+3 ) {
				 listaEmpresaA.get(j).add(paises[z]);
				 listaEmpresaA.get(j+1).add(paises[z] + " Gold");
				 listaEmpresaA.get(j+2).add(paises[z] + " sin Gold");
			 }
		 }
								
		
		
		 try {
             //create .xls and create a worksheet.
             FileOutputStream fos = new FileOutputStream("D:\\probando.xls");
             HSSFWorkbook workbook = new HSSFWorkbook();
             HSSFSheet worksheet = workbook.createSheet("XboxOne");
             
             //Escribimos en el Excel toda la información
            	int l=0;
            	
            		//Recorremos las filas
                 for (int f=0; f< listaEmpresaA.get(0).size() ; f++) {
                 	HSSFRow fila = worksheet.createRow(f);
                 	
                 	//Recorremos las columnas
                 	for(int c=0;c<total_columnas;c++){
                 		   HSSFCell celda = fila.createCell(c);
                 		   celda.setCellValue(listaEmpresaA.get(c).get(f));
                 		   l++;
                 		   
                 	}	   
                 }

         	
         
         	

                                  
            //Save the workbook in .xls file
             workbook.write(fos);
             fos.flush();
             fos.close();
         } catch (FileNotFoundException e) {
             e.printStackTrace();
         } catch (IOException e) {
             e.printStackTrace();
         }

The problem is that the output should be:

Juegos / España / España Gold / España Sin Gold / USA / USA Gold / USA sin Gold;

But instead of this I receive:

Juegos / España / España Gold / España Sin Gold / España / España Gold / España Sin Gold;

The value for países[1] is USA not España…and I don´t see anything wrong in the for conditional.

The the code following is just to introduce it in an Excel.

Thanks in advice.

Hi @egoicantero. I’ll move your topic to the General Web Development section where you might get more of a response than here in the JavaScript section.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.