Ich habe diese Klasse:Kann nicht Beispiel kompilieren
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)
}
Und diese Testklasse:
import Rational
object Test extends App {
val x = new Rational(1/2)
println("hello");
}
Ich versuche, sie
scalac Test.scala Rational.scala
mit zu kompilieren, aber ich bekomme die folgende Fehler:
Test.scala:3: error: '.' expected but ';' found.
object Test extends App {
^
one error found
Kann mir jemand sagen warum er nicht kompiliert. Dies ist ein Grundfehler
entfernen 'Import Rational' brauchen – pamu