【发布时间】:2013-01-08 08:24:51
【问题描述】:
我在处理这个PrintWriter 时遇到了一些问题,它在for 循环之外工作,它确实打印了“Test1”和“Test2”,但它没有在If 内打印“example 1”
这行代码在我用调试器检查时被执行
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);
}
【问题讨论】:
-
您是如何检查该行是否实际执行的?
-
你会因为使用
continue作为方法名而编译失败! -
我已将单词更改为“继续”,以便将其发布在 StackOverflow 上,因为原始代码是另一种“语言”,所以应该不是问题
-
在这种情况下,显示
continue(...)方法是合适的 -
该方法有效,因为如果我尝试使用
System.out.println输出它,它会在控制台中打印它。