gpt4 book ai didi

Java:不兼容的类型(int/boolean)

转载 作者:行者123 更新时间:2023-12-01 18:44:36 25 4
gpt4 key购买 nike

import java.io.*;
public class AdamHmwk4 {
public static void main(String [] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

int counter1;
int counter2;
int counter3;
String answer = "";

System.out.println("Welcome to Adam's skip-counting program!");
System.out.println("Please input the number you would like to skip count by.");
counter1 = Integer.parseInt(br.readLine());

System.out.println("Please input the number you would like to start at.");
counter2 = Integer.parseInt(br.readLine());

System.out.println("Please input the number you would like to stop at.");
counter3 = Integer.parseInt(br.readLine());

System.out.println("This is skip counting by" + counter1 + ", starting at" + counter2 + "and ending at" + counter3 +":");

while (counter2 = counter3) {
counter2 = counter2 + counter1;
counter3 = counter2 + counter1;
}
}
}

我正在尝试制作跳过计数程序。当我编译此代码时,行 while(counter2 = counter3){ 显示为不兼容类型错误。编译器说它找到了一个“int”,但它需要一个“boolean”。请记住,我是新手,所以我还没有在 Java 类中学习 boolean 值。

最佳答案

您不能将值与赋值运算符 = 进行比较。使用 == 来比较您的值。改变

while(counter2 = counter3){

while(counter2 == counter3){

这是一个introductory page for Java operators .

关于Java:不兼容的类型(int/boolean),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18325314/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com