0

我得到找不到符号错误。我正在制作一个可以执行各种数学运算的程序。我在这里收到错误:

a=Double.parseDouble(in.readLine());

错误是:

cannot find symbol- method readLine()

我正在给我的整个程序:

// I(Rachit Bhargava) am writing my first program that includes almost every feature of Mathematical Operations.
import java.io.*;
import java.lang.*;
import java.lang.Math;
public class All_In_One
{
    public static void main(String args[])throws IOException
    {
        InputStreamReader in = new InputStreamReader(System.in);
        BufferedReader read = new BufferedReader(read);
        double a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, r, s, t, u, v, w, x, y, z, i1, a1, i2, a2;
        char ch1, ch2;
        System.out.println("To which topic is your question based upon?");
        System.out.println("Enter 'm' for Mathematics and 'g' for Geometry");
        System.out.println("Please enter your choice.");
        ch1= (char)(in.read());
        switch (ch1)
        {
            case 'm':
            System.out.println("What operation do you want to do?");
            System.out.println("Enter 'a' for addtion, 's' for subtraction, 'm' for multiplication, 'd' for division, 't' for finding out simple interest(with amount), 'c' for finding out compound interest(with amount) and 'b' for finding out both(with amount) and their difference");
            System.out.println("Please enter your choice.");
            ch2= (char)(in.read());
            switch (ch2)
            {
                case 'a':
                System.out.println("Please enter first number.");
                a=Double.parseDouble(in.readLine());
                System.out.println("Please enter second number.");
                b=Double.parseDouble(in.readLine());
                c = a+b;
                System.out.println("Sum = "+c);
                break;
                case 's':
                System.out.println("Please enter first number.");
                a=Double.parseDouble(in.readLine());
                System.out.println("Please enter second number.");
                b=Double.parseDouble(in.readLine());
                c = a-b;
                System.out.println("Difference = "+c);
                break;
                case 'm':
                System.out.println("Please enter first number.");
                a=Double.parseDouble(in.readLine());
                System.out.println("Please enter second number.");
                b=Double.parseDouble(in.readLine());
                c = a*b;
                System.out.println("Answer = "+c);
                break;
                case 'd':
                System.out.println("Please enter first number.");
                a=Double.parseDouble(in.readLine());
                System.out.println("Please enter second number.");
                b=Double.parseDouble(in.readLine());
                c = (a>b)? (a/b):(b/a);
                System.out.println("Answer = "+c);
                break;
                case 't':
                System.out.println("Please enter principal");
                p=Double.parseDouble(in.readLine());
                System.out.println("Please enter rate of interest.");
                r=Double.parseDouble(in.readLine());
                System.out.println("Please enter time(in years)");
                t=Double.parseDouble(in.readLine());
                i = p*r*t/100;
                a = p+i;
                System.out.println("Simple interest = "+i);
                System.out.println("Amount = "+a);
                break;
                case 'c':
                System.out.println("Please enter principal");
                p=Double.parseDouble(in.readLine());
                System.out.println("Please enter rate of interest.");
                r=Double.parseDouble(in.readLine());
                System.out.println("Please enter time(in years)");
                t=Double.parseDouble(in.readLine());
                a = p*(Math.pow(((100+r)/100), t));
                i = a-p;
                System.out.println("Compound Interest = "+i);
                System.out.println("Amount = "+a);
                break;
                case 'b':
                System.out.println("Please enter principal");
                p=Double.parseDouble(in.readLine());
                System.out.println("Please enter rate of interest.");
                r=Double.parseDouble(in.readLine());
                System.out.println("Please enter time(in years)");
                t=Double.parseDouble(in.readLine());
                i1 = p*r*t/100;
                a1 = p+i1;
                a2 = p*(Math.pow(((100+r)/100), t));
                i2 = a-p;
                d = a2-a1;
                System.out.println("Simple interest = "+i1);
                System.out.println("Amount(as by simple interest) = "+a1);
                System.out.println("Compound Interest = "+i2);
                System.out.println("Amount(as by compound interest) = "+a2);
                System.out.println("Difference in interests and amount = "+d);
                break;
                default:
                System.out.println("Invalid input :(");
            }
            break;
            case 'g':
            System.out.println("Work In Progress!");
            break;
            default:
            System.out.println("Invalid Input :(");
        }
        System.out.println("Thank you for using my program");
        System.out.println("All credits goes to Rachit Bhargava");
    }
}

请帮我解决这个问题!

4

4 回答 4

0

正如您在InputStreamReaderjavadoc 中看到的,没有readLine方法。也许你想使用readLine你的BufferedReader read变量中的方法,因为这个方法:BufferedReader

b = Double.parseDouble(read.readLine());

顺便一提:

  • 这一行:

    BufferedReader read = new BufferedReader(read);
    

    应该:

    BufferedReader read = new BufferedReader(in);
    

    编译的事实并不意味着它会按预期工作。

  • 我建议您将变量名称更改为更有意义的名称,例如buffReader代替readfirstNumber代替asecondNumber代替b,等等......

于 2013-11-04T05:53:13.320 回答
0

那是因为InputStreamReader没有readLine()方法。你需要使用BufferedReader

更改您的代码:

InputStreamReader in = new InputStreamReader(System.in);
BufferedReader read = new BufferedReader(read);

至:

InputStreamReader in = new InputStreamReader(System.in);
BufferedReader read = new BufferedReader(in);

然后您可以执行以下操作:

a = Double.parseDouble(read.readLine());

或者,您可以使用Scanner这将允许您执行以下操作Scanner.nextDouble()

Scanner scanner = new Scanner(System.in);
double a = scanner.nextDouble();
于 2013-11-04T05:53:26.420 回答
0

您需要进行以下 2 项更改:

  1. InputStreamReader in = new InputStreamReader(System.in);
    BufferedReader read = new BufferedReader(in);
    
  2. 使用 read.readLine() 而不是 in.readLine(); 如,

    a=Double.parseDouble(read.readLine());

于 2013-11-04T05:55:09.447 回答
0

InputStreamReader类没有readLine方法。扫描仪是收集用户输入的更好选择。

于 2013-11-04T05:52:37.933 回答