尝试输入一个 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/