gpt4 book ai didi

Java无法通过设置默认值找到符号错误

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

尝试输入一个 while 循环,允许用户输入数字和运算符。我正在尝试设置任何默认值,例如 char operator = x;进入循环本身,但我一直收到找不到符号错误。我做错了什么?

  BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
String inputValues;

// Sets the variable defaults
double accumulator = 0;
double newVal;
char operator = x; // Here is where I get my error

// Create the loop here
while (operator != 't' && operator != 'T') {

// Takes user input values here
inputValues = input.readLine();
String[] inputValue = inputValues.split("\\s+");

// Sets accumulator number and operator value
accumulator = Double.parseDouble(inputValue[0]);
operator = inputValue[1].charAt(0);

最佳答案

这不是设置char的方式。您需要使用单引号。

char operator = 'x';

您应该考虑查看有关基本类型的 Java 文档:http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

关于Java无法通过设置默认值找到符号错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28222142/

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