为什么我收到错误:在Java中找不到符号?

时间:2014-04-26 11:22:34

标签: java

为什么我在编译时找不到符号错误?我找不到任何错误 上面是两个文件,一个包含类'FractionSecond',另一个包含main,'FractionSecondDemo'。我尝试了不同的东西。

public class FractionSecond  
{  
    int numerator;  
    int denominator;

    double fraction;
    public FractionSecond(int numerator, int denominator)
    {
        this.numerator=numerator;
        this.denominator=denominator;
    }
    public double Fraction()
    {
        fraction=(double)numerator/denominator;
        return fraction;
    }
    public String lowestTerm()
    {
        if(numerator>denominator)
        {
            int checkNumerator=numerator;
            int checkDenominator=denominator;
            do
            {
             int remainder=checkNumerator%checkDenominator;
             checkNumerator=checkDenominator;
             checkDenominator=remainder;
            }while(remainder!=0);
            numerator=numerator/checkNumerator;
            denominator=denominator/checkNumerator;
            return numerator+"/"+denominator;
        }
    }

}

public class FractionSecondDemo
{ 
     public static void main(String[] args)
    {
        FractionSecond trial=new FractionSecond(1215,1134);
        trial.fraction();
    }
}

我正在

FractionSecondDemo.java:6: error: cannot find symbol
        trial.fraction();    
         ^
  symbol:   method fraction()    
  location: variable trial of type FractionSecond  
1 error

2 个答案:

答案 0 :(得分:1)

您的FractionSecond类中没有这样的方法fraction()。有方法Fraction()。现在你知道java是case-sencitive。

答案 1 :(得分:0)

您提交的分数是私有的,但分数方法是公开的。好像你想调用方法一个。所以你应该写

trial.Fraction();