Arithmetic/Integer: Difference between revisions
→{{header|Kotlin}}: Removed error handling (as specified by the task) and made the code use the Kotlin standard library instead of the Java standard library.
(→{{header|Ruby}}: added divmod) |
(→{{header|Kotlin}}: Removed error handling (as specified by the task) and made the code use the Kotlin standard library instead of the Java standard library.) |
||
Line 2,816:
=={{header|Kotlin}}==
<syntaxhighlight lang="
import kotlin.math.pow // not an operator but in the standard library
fun main(
val r = Regex("""-?
val input: String = readLine()!!.trim()
▲ print("Enter two integers separated by space(s) or q to quit: ")
val b = input.substring(index
println("$a - $b = ${a -
println("$a * $b = ${a * b}")
▲ val a = input.substring(0, index).trimEnd().toLong()
println("$a ^
}
▲ 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
}</syntaxhighlight>
{{out}}
<pre>
Enter two integers separated by space(s)
2 + 63 = 65
2 - 63 = -61
Line 2,866 ⟶ 2,843:
2 / 63 = 0
2 % 63 = 2
2 ^ 63 =
</pre>
|