java - "cannot find symbol"错误

标签 java variables calculator undefined-symbol

我正在制作一个非常基本的计算器程序(我对 Java 还很陌生。)我使用 java.io.Console 包从命令行输入,我的代码如下所示:

import java.io.Console;

public class calculator {

public static void main(String args[]) {

Console console = System.console();
int exit = 1;


System.out.println("Calculator v1.0 by rulla101");
System.out.println(" ");

String inputselect = console.readLine("Type add, sub, mlt, or div to select operation: ");

if (inputselect == "add") {

//ADDING!!!
while(exit > 0) {

String input1a = console.readLine("Input number 1: ");
int a = Integer.parseInt(input1a);

String input2a = console.readLine("Input number 2: ");
int b = Integer.parseInt(input2a);

System.out.println("The answer is:");
System.out.println(a+b);

String exitstringa = console.readLine("Type 0 to exit, type 1 to add two more numbers: ");
int extseta = Integer.parseInt(exitstringa);

if(extseta == 0){
    exit--; 
    }
}

}
else if (inputselect == "sub") {

//SUBTRACTING!

while(exit > 0) {

String input1s = console.readLine("Input number 1: ");
int c = Integer.parseInt(input1s);

String input2s = console.readLine("Input number 2: ");
int d = Integer.parseInt(input2s);

System.out.println("The answer is:");
System.out.println(c-d);

String exitstrings = console.readLine("Type 0 to exit, type 1 to subtract two more numbers: ");
int extsets = Integer.parseInt(exitstrings); 

if(exitsets == 0){
    exit--;
}

}

}
else if (inputselect == "mlt"){

//MULTIPLYING!!

while(exit > 0) {

String input1m = console.readLine("Input number 1: ");
int e = Integer.parseInt(input1m);

String input2m = console.readLine("Input number 2: ");
int f = Integer.parseInt(input2m);

System.out.println("The answer is:");
System.out.println(e*f);

String exitstringm = console.readLine("Type 0 to exit, type 1 to multiply two more numbers: ");
int extsetm = Integer.parseInt(exitstringm); 

if(exitsetm == 0){
    exit--;
}
}
}
else if (inputselect == "div"){

//DIVIDING!!

while(exit > 0) {

String input1d = console.readLine("Input number 1: ");
int g = Integer.parseInt(input1d);

String input2d = console.readLine("Input number 2: ");
int h = Integer.parseInt(input2d);

System.out.println("The answer is:");
System.out.println(g/h);

String exitstringd = console.readLine("Type 0 to exit, type 1 to divide two more numbers: ");
int extsetd = Integer.parseInt(exitstringd); 

if(exitsetd == 0){
    exit--;
}
}
}
}
}

但是当我尝试编译该程序时,我得到了这个:

/Users/ethan/javafolder/calculator/calculator.java:58: cannot find symbol
symbol  : variable exitsets
location: class calculator
    if(exitsets == 0){
       ^
/Users/ethan/javafolder/calculator/calculator.java:83: cannot find symbol
symbol  : variable exitsetm
location: class calculator
    if(exitsetm == 0){
       ^
/Users/ethan/javafolder/calculator/calculator.java:106: cannot find symbol
symbol  : variable exitsetd
location: class calculator
    if(exitsetd == 0){
       ^
3 errors


Done

我不明白......有问题的变量之前没有定义过或任何东西......而且我很确定它们存在于代码中......任何人都可以找出错误吗?

(附注:我知道它确实庞大且臃肿,我可能可以用一半的行数来完成它,但请耐心等待。)

-rulla101

最佳答案

查看三个错误。

int extsets = Integer.parseInt(exitstrings); 

if(exitsets == 0){ //must be extsets
    exit--;
}


int extsetm = Integer.parseInt(exitstringm); 

if(exitsetm == 0){  //must be  extsetm
    exit--;
}


int extsetd = Integer.parseInt(exitstringd); 

if(exitsetd == 0){  //must be extsetd
    exit--;
}

关于java - "cannot find symbol"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7775372/

相关文章:

java - 从 SQLite 获取数据到 Recyclerview 它导致我为 null

c++ - 创建具有指定字符数的字符串

variables - Swift - 替换字符串中的字符

C++ 对我的命令行计算器进行故障排除

c# - C# 中有数学 Gamma 函数吗?

calculator - 如何为 TI-89 中的函数返回值?

java - 为什么这个文本面板给我一个内存地址?

java - 检查数据库中是否存在表

java - 奇怪的 Apache Camel 异常

ruby - 如何在 ruby​​ 中将符号作为 post 请求的参数传递?