27 lines
639 B
Kotlin
27 lines
639 B
Kotlin
package drills.drill03.exercise3
|
|
|
|
import util.rmi.Client
|
|
|
|
fun main() {
|
|
Client(clientHandler).start()
|
|
}
|
|
|
|
val clientHandler = {
|
|
val rev = Client.lookup("rev") as Rev
|
|
|
|
println("Enter two numbers:")
|
|
val a = readLine()?.toInt() ?: 0
|
|
val b = readLine()?.toInt() ?: 0
|
|
|
|
val sum = rev.executeTask(AddTask(a, b))
|
|
println("The sum of $a and $b is $sum")
|
|
|
|
println("Enter the number of which you want to calculate the factorial:")
|
|
val n = readLine()?.toInt() ?: 0
|
|
|
|
val fact = rev.executeTask(FactTask(n))
|
|
println("The factorial of $n is $fact")
|
|
}
|
|
|
|
fun fact(n: Int): Long = if (n <= 1) 1 else n * fact(n - 1)
|