Back to questions
JuniorTheoryCommon
What does the program print?
public class Main {
public static void main(String[] args) {
System.out.print(7 / 2);
System.out.print(" ");
System.out.println(-7 % 3);
}
}3 -1
- Expecting
3.5: dividing oneintby another drops the fraction, so7 / 2is3. - Expecting a non-negative remainder, as in math: in Java the remainder takes the sign of the dividend, so
-7 % 3is-1.
- How would you change the expression so that the division prints
3.5? - What does
7 % -3evaluate to, and why?