java - 必需的: variable Found:value Error Java Text-B

你好堆栈溢出。

我的代码有问题。目标是创建一个基于文本的计算器,该计算器可读取输入文件并处理方程式。第一个数字告诉程序那里有多少行。我想我正确地设置了那部分,计数是行数。这是到目前为止我得到的。

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;
        }
    }

目标是使程序遵循多个“if”语句。我了解这一部分,但我无法克服此错误。文本文件的第一行读取一个整数,我试图查看该文件的第二行,该行读取double的sin并对其进行计算并存储它。帮助将不胜感激!

最佳答案

更改已在注释中。

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/

相关文章:

java - 创建了一个新的Android项目,在手机上运行时崩溃

java - vlcj 在尝试创建服务器流时出错

c++ - 错误编译 Unresolved external 错误

android - 空载Map Android-Google Maps V2

java - Java博士;为什么不编译呢?

c++ - 错误 : too many template-parameter-lists

c++ - Visual Studio编译错误查找文件

c++ - main.obj : error LNK2019: unresolved externa

java - Java找不到符号,错误

java - 如何调用其他类(class)的名单?