mercredi 7 février 2018

How to write change values of elements in an array using if else statement and write them to excel?

I have written a code in java where the array has two elements,their values changes by if else statement.The console shows right answer.But in the excel sheet the values for both the elements are zero. Is there anything that I am missing in the code?

 int StartState=0;
           int EndState=0;
         
                 Object[][] TransProbArray = {
                     {StartState,EndState},
                     
             };
                 
      
      StartState=1;
      if(StartState==1) {
          EndState=2;
      }else {
          EndState=4;
      }
      
      System.out.println(EndState);
     
      StartState=2;
      if(StartState==2) {
         EndState=4;
       }else{ 
         EndState=5;
       }
        System.out.println(EndState);
                 
                  
        int rowCount = sheet.getLastRowNum();
             for (Object[] TPA : TransProbArray) {
            
            Row row = sheet.createRow(++rowCount);
            int columnCount = 0;
             
            for (Object field : TPA) {
                Cell cell = row.createCell(columnCount++);
                if (field instanceof String) {
                    cell.setCellValue((String) field);
                } else if (field instanceof Integer) {
                    cell.setCellValue((Integer) field);
                }else  if (field instanceof Double) {
                    cell.setCellValue((Double) field);
            }
            }
        } 
            

Aucun commentaire:

Enregistrer un commentaire