2023-05-08 10:44:41 +03:00
|
|
|
package OOP.Java.lab_1
|
|
|
|
|
2023-05-07 23:14:24 +03:00
|
|
|
fun protectedInput(variableName: String): Int {
|
|
|
|
do {
|
|
|
|
try {
|
2023-05-07 23:15:50 +03:00
|
|
|
print("Enter $variableName: ")
|
2023-05-07 23:15:28 +03:00
|
|
|
return readln().toInt()
|
2023-05-07 23:14:24 +03:00
|
|
|
} catch (e: Exception) {
|
2023-05-07 23:15:50 +03:00
|
|
|
println("${variableName.uppercase()} must be an integer!")
|
2023-05-07 23:14:24 +03:00
|
|
|
}
|
|
|
|
} while (true)
|
|
|
|
}
|
|
|
|
|
|
|
|
fun main() {
|
2023-05-07 23:15:28 +03:00
|
|
|
val n: Int = protectedInput("n")
|
|
|
|
val m: Int = protectedInput("m")
|
|
|
|
val a: Int = protectedInput("a")
|
|
|
|
val b: Int = protectedInput("b")
|
2023-05-07 23:14:24 +03:00
|
|
|
|
2023-05-07 23:15:28 +03:00
|
|
|
val s: Float = (b + m).toFloat() / 2 * (m - b + 1) * (n - a + 1)
|
2023-05-07 23:14:24 +03:00
|
|
|
|
|
|
|
println("S = $s")
|
|
|
|
}
|