你好堆栈溢出。
我的代码有问题。目标是创建一个基于文本的计算器,该计算器可读取输入文件并处理方程式。第一个数字告诉程序那里有多少行。我想我正确地设置了那部分,计数是行数。这是到目前为止我得到的。
Scanner equationScan;
int count;
double a=0;
double b=0;
double calc1;
equationScan = new Scanner(new File("calculator.txt"));
count = equationScan.nextInt();
while(count > 0)
{
String line = equationScan.nextLine();
if(line.equals("sin"))
{
a = equationScan.nextDouble(); *Error shows up here. Req: variable Found: value
Math.sin(a)= calc1;
}
}
最佳答案
更改已在注释中。
package calculator;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class calc {
public static void main(String[] args) {
Scanner equationScan = null;
int count;
double a=0;
double b=0;
double calc1;
try { //optional: add a try catch block to catch FileNotFoundException exception
equationScan = new Scanner(new File("calculator.txt"));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
count = equationScan.nextInt();
equationScan.nextLine(); //add a nextline() according to what TOM pointed
while(count > 0)
{
String line = equationScan.nextLine();
if(line.equals("sin"))
{
String value=equationScan.nextLine(); //Parse the double to a string
a=Double.parseDouble(value);
calc1 = Math.sin(a) ; //Assignment should be at the right sign of the = operator
}
}
}
}
关于java - 必需的: variable Found:value Error Java Text-Based Calculator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26444521/