Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
17
Task/Arithmetic-Integer/Kotlin/arithmetic-integer.kotlin
Normal file
17
Task/Arithmetic-Integer/Kotlin/arithmetic-integer.kotlin
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import kotlin.math.pow // not an operator but in the standard library
|
||||
|
||||
fun main() {
|
||||
val r = Regex("""-?[0-9]+\s+-?[0-9]+""")
|
||||
print("Enter two integers separated by space(s): ")
|
||||
val input: String = readLine()!!.trim()
|
||||
val index = input.lastIndexOf(' ')
|
||||
val a = input.substring(0, index).trimEnd().toLong()
|
||||
val b = input.substring(index + 1).toLong()
|
||||
println("$a + $b = ${a + b}")
|
||||
println("$a - $b = ${a - b}")
|
||||
println("$a * $b = ${a * b}")
|
||||
println("$a / $b = ${a / b}") // rounds towards zero
|
||||
println("$a % $b = ${a % b}") // if non-zero, matches sign of first operand
|
||||
println("$a ^ $b = ${a.toDouble().pow(b.toDouble())}")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue