Back to questions
JuniorTheoryCommon
What does the program print?
print(7 / 2, -7 % 3)3 -1
- Expecting
3 2, as in math: in Swift the remainder takes the sign of the dividend.-7 / 3is-2, and-2 * 3 + (-1)gives-7, so-7 % 3is-1. - Expecting
3.5: dividing oneIntby another drops the fraction, so7 / 2is3. A fraction needsDoublenumbers, such as7.0 / 2.
- What does
print(-7 / 2)print, and why not-4? - How do you get
3.5from twoIntconstants holding7and2?