Added a Kotlin variation.
This commit is contained in:
parent
5ca9ab6c17
commit
64c9e43742
|
@ -2,7 +2,7 @@ fun protectedInput(variableName: String): Int {
|
||||||
do {
|
do {
|
||||||
try {
|
try {
|
||||||
print("Enter $variableName: ");
|
print("Enter $variableName: ");
|
||||||
return readln().toInt();
|
return readln().toInt()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
println("${variableName.uppercase()} must be an integer!");
|
println("${variableName.uppercase()} must be an integer!");
|
||||||
}
|
}
|
||||||
|
@ -10,12 +10,12 @@ fun protectedInput(variableName: String): Int {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
val n: Int = protectedInput("n");
|
val n: Int = protectedInput("n")
|
||||||
val m: Int = protectedInput("m");
|
val m: Int = protectedInput("m")
|
||||||
val a: Int = protectedInput("a");
|
val a: Int = protectedInput("a")
|
||||||
val b: Int = protectedInput("b");
|
val b: Int = protectedInput("b")
|
||||||
|
|
||||||
val s: Float = (b + m).toFloat() / 2 * (m - b + 1) * (n - a + 1);
|
val s: Float = (b + m).toFloat() / 2 * (m - b + 1) * (n - a + 1)
|
||||||
|
|
||||||
println("S = $s")
|
println("S = $s")
|
||||||
}
|
}
|
Loading…
Reference in New Issue