类型不匹配:在while循环中无法从int转换为boolean [英] Type mismatch: cannot convert from int to boolean in while loop
问题描述
我刚刚开始学习java,试图找到答案,但我想我不够聪明。
我正在尝试将一个数组从一些文件写入另一个文件。
I just started learning java, tried to find the answer but I guess I'm not smart enough. I'm trying to write an array which I got from some file into another file.
问题是当我试图制作while时它说不能从int转换为boolean。任何人都可以提出建议先感谢您。
这就是我所拥有的:
The problem is when I'm trying to make "while" it's saying cannot convert from int to boolean. Can anyone suggest something. Thank you in advance. This is what I have :
public void savethefile() throws IOException{
File file1= new File("lala.ppm");
FileWriter save=new FileWriter(file1);
save.write(tytul);
while(i){
save.write(arraycomment[i]);
i++;
}
save.close();
推荐答案
据推测我
是 int
,而不是 boolean
。与C / C ++不同,它不会隐式转换为 boolean
。您必须明确说明您的条件为布尔
。
Presumably i
is an int
, not a boolean
. Unlike C/C++, this won't be converted to a boolean
implicitly. You must explicitly state your condition as a boolean
.
while (i < arraycomment.length) // or some other constant
这篇关于类型不匹配:在while循环中无法从int转换为boolean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!