0

我遇到了一些麻烦PrintWriter,它在循环之外工作for,它确实打印了“Test1”和“Test2”,但它没有在里面打印“example 1”If

当我用调试器检查它时,代码行被执行

 File file = new File ("output.txt");
 FileWriter wri;
 try {
    wri = new FileWriter(file);

    PrintWriter writer = new PrintWriter(wri);
    writer.println("Test1");

    boolean result=false;

    for(i=0;i<this.lung;i++){

       for(j=0;j<this.lung;j++){

            if(wordToFind.charAt(0)==mat[i][j]){

                if((i>=wordLength-1)&&(results!=true))
                    if (wordToFind.charAt(1)==mat[i-1][j])
                        if(result=continue(i,j,i-1,j,1))
                            writer.println("example 1");
                  /*Same if as the above but with differente parameters are down here*/
                  }
             } 
         }
      }
      writer.print("Test2");
      writer.close();

  } catch (IOException e) {
      System.out.println("Error: " + e);
 }
4

1 回答 1

0

这两个results/result相同的变量是否,如果是,则尝试将第一个更改为result

//假设'因为我没有results boolean在你的代码中找到任何变量

if((i>=wordLength-1)&&(results!=true))  // results -> result
                    if (wordToFind.charAt(1)==mat[i-1][j])
                        if(result=continue(i,j,i-1,j,1)) 
                            writer.println("example 1");
于 2013-01-08T09:12:00.757 回答