首页 > 解决方案 > 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.

标签: java

解决方案


=是分配,您需要在循环的第二项进行比较。

for(int counter=0;counter=max-4;counter++) {

应该

for (int counter = 0; counter < max - 4; counter++) {

(添加了空格,但注意<是一个比较......也许你想要<=)。


推荐阅读