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