获取“无法找到符号”错误

时间:2013-11-04 05:50:41

标签: java

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

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 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

正如您在InputStreamReader javadoc中看到的那样,没有readLine方法。您可能希望使用readLine变量中的BufferedReader read方法,因为BufferedReader 此方法:

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

顺便说一下:

  • 这一行:

    BufferedReader read = new BufferedReader(read);
    

    应该是:

    BufferedReader read = new BufferedReader(in);
    

    编译并不意味着它将按预期工作。

  • 我建议您更改变量名称以获取更有意义的内容,例如buffReader而不是readfirstNumber而不是a,{ {1}}代替secondNumber,依此类推......

答案 2 :(得分: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());

或者,您可以使用ScannerScanner.nextDouble()

Scanner scanner = new Scanner(System.in);
double a = scanner.nextDouble();

答案 3 :(得分:0)

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

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

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