2016-12-11 6 views
0

각 행에 열 번호, 행 번호, 세부 정보가있는 파일을 읽었습니다. 파일은 열 다음에 정렬됩니다. 올바른 행과 열의 CSV 파일에 세부 사항을 배치하고 싶습니다. 그래서 행 번호의 변경을 테스트 한 다음 줄 바꿈 ("\ n")을 추가합니다.GWT Java - 서버 측 "for 루프"가 작동하지 않습니다.

for 루프의 각면에있는 System.out.println이 로그에 표시되는 것이 문제입니다. 그러나, 그 자체가 트리거되지 루프 (즉, 줄 바꿈이 추가되지 않고에서 System.out.println는 로그에 표시되지 않는

코드는 다음과 같습니다.

System.out.println("New row - " + Integer.parseInt(report.getReportDetailRow())+ " greater than current row - " + currentRow); 
      currentCol = 0; 
      //Add line breaks 
      int j = Integer.parseInt(report.getReportDetailRow()); 
      for(int i = currentRow; i > j; i++){ 
       System.out.println("Append line break"); 
       fileContent.append("\n"); 
      } 
      System.out.println("After append"); 
      currentRow = Integer.parseInt(report.getReportDetailRow()); 
      if (currentCol == Integer.parseInt(report.getReportDetailColumn())){ 
       fileContent.append(report.getReportDetailDetails() + ","); 
       currentCol++; 
      }else{ 
       //Add columns 
       for(int i = currentCol; i == Integer.parseInt(report.getReportDetailColumn()); i++){ 
        fileContent.append(","); 
       } 
       fileContent.append(report.getReportDetailDetails() + ","); 
       currentCol = Integer.parseInt(report.getReportDetailColumn()); 
      } 

있습니다 나는 결과를 강제하려고 "내가 == J"대신 "난> J"를 사용했다.

+0

'i' 보통'j' 무엇 i==j 또는 i<j 중 하나에이 문제를 해결하기 위해 루프 내부의 조건문을 변경할 수 있습니다? 'i == j'가 있다면, 한 번만 실행될 것입니다.'i Iluvatar

+0

안녕하세요 Iluvatar, 저는 Glyn

답변

1

을 명세서에서 행을 반복을 위해, 당신이 가지고있는 번호가

for(int i = currentRow; i > j; i++) 

j 경우 영형 f 현재 행을 찾으려면 조건을 모두 i < j으로 변경해야합니다.

0
for(int i = currentRow; i > j; i++) { 
    System.out.println("Append line break"); 
    fileContent.append("\n"); 
} 

루프 위 중 무한 루프가 발생할 것 또는 전혀은

  • 무한 i 경우 이미 j보다 큰 (귀하의 경우) 트리거 얻을. 모든 반복마다 i++으로 끝나지 않을 것입니다.
  • 조건이 i>j이므로 ij보다 작 으면 실행하지 마십시오.

당신은

for(int i = currentRow; i == j; i++) // in which case replacing this with an `if(i==j)` would do the needful 

또는

for(int i = currentRow; i < j; i++) // to iterare from initial i upto j