I came across this old question and did the following experiment with scala 2.10.3.
I rewrote the Scala version to use explicit tail recursion:
impor
To make the Java version completely equivalent to your Scala code you need to change it like this.
private int t = 20;
private int t() {
return this.t;
}
private void run() {
int i = 10;
while (!isEvenlyDivisible(2, i, t()))
i += 2;
System.out.println(i);
}
It is slower because the JVM can not optimize the method calls.