0
我有这个类:不能编译例如
class Rational(n:Int, d:Int) {
require(d!=0)
private val g = gcd(n.abs, d.abs)
val numer = n/g
val denom = d/g
def this(n: Int) = this(n, 1);
def add(that:Rational): Rational = new Rational(numer * that.denom + that.numer * denom, denom * that.denom)
override def toString = numer+"/"+denom;
private def gcd(a: Int, b: Int): Int = if(b==0) a else gcd(b, a % b)
}
而这个测试类:
import Rational
object Test extends App {
val x = new Rational(1/2)
println("hello");
}
我试图使用
scalac Test.scala Rational.scala
编译他们,但我得到以下错误:
Test.scala:3: error: '.' expected but ';' found.
object Test extends App {
^
one error found
有人可以指导我为什么不编译。这是一个基本错误
删除'进口Rational' – pamu