java - How can I correct this int to boolean error?
问题描述
Sorry I am having a mental block, can anyone see why I get the 'cannot convert from int to boolean' error message. Much appreciated
public static void main (String[]args) {
int max=10;
int sum=0;
int count=0;
for(int counter=0;counter=max-4;counter++) {
sum=max-4;
count=max-3;
for(sum=3;sum<5;sum++) {
if(count==0 && max>0){
System.out.println("Hello");
} else if (count<4) {
System.out.println("Go for it");
} else {
System.out.println("OK");
}
}
}
sum=sum+count;
System.out.println("Total = "+sum);
System.out.println("Max = "+count);
}
I feel like I have checked using the '==' for the if condition.
解决方案
=
是分配,您需要在循环的第二项进行比较。
for(int counter=0;counter=max-4;counter++) {
应该
for (int counter = 0; counter < max - 4; counter++) {
(添加了空格,但注意<
是一个比较......也许你想要<=
)。
推荐阅读
- c# - 带有 application/x-www-form-urlencoded HTTP POST 的 ASP.NET Web api 映射模型
- java - Java Nashorn 的替代品
- docker - Kubernetes:weave 在其中一个工作节点上选择了公共 IP
- android - 有没有办法使用 declare-styleable 打开选择资源对话框,让您在 Android Studio 中选择颜色或可绘制对象?
- regex - 如何将所有非单词字符更改为破折号并在一个正则表达式中修剪破折号字符串?
- python - python 如何从 2019 年 12 月和两个日期列之间查找每个月的天数
- python - 如何在 Python 中向字典键添加多个值
- group-by - 根据 Google Big Query 中的案例分组和求和
- ssas - SSAS - 向事实表添加新字段而不会出错
- python - 使用 jquery/ajax 显示来自服务器的 JSON 数据