Type mismatch: cannot convert from int to boolean in while loop(类型不匹配:无法在 while 循环中从 int 转换为 boolean)
问题描述
我刚开始学习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();
推荐答案
大概 i 是一个 int,而不是 boolean.与 C/C++ 不同,这不会被隐式转换为 boolean.您必须将您的条件明确声明为 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:类型不匹配:无法在 while 循环中从 int 转换为 boolean
基础教程推荐
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- Struts2 URL 无法访问 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
