Back to questions
JuniorTheoryCommon
What does the program print?
fun main() {
println("${7 / 2} ${-7 % 3} ${7 / 2.0}")
}3 -1 3.5
- Expecting
3.5for7 / 2: dividing oneIntby another drops the fraction, so7 / 2is3; only7 / 2.0, with aDouble, gives3.5. - Expecting a non-negative remainder, as in math: in Kotlin the remainder takes the sign of the dividend, so
-7 % 3is-1.
- What happens when the program computes
7 / 0, and what about7.0 / 0? - How do you get
3.5from twoIntvariablesa = 7andb = 2?