Welcome to the CSC Q&A, where you can get help (and share your knowledge) about computer science!

What would happen if you tried to calculate 2 % 10?

+3 votes
What happens when you try to calculate the remainder when the first number is smaller than the second? Would it result in a "no solution" or zero?
asked Aug 30 in CSC 211 (F17) by Lauren Endress (100 points)

1 Answer

+3 votes
Well modulus divides and provides the left over value. So you would divide 2 / 10 which would equal 0 (not very relevant) then the left over number is 2. So 2 % 10 = 2

Here some other examples:

5 % 2 = 1

4 % 3 = 1

104 % 20 = 4

101 % 102 = 101
answered Aug 30 by Daniel Zwiener (100 points)
Yes.  As Daniel (from 285) says, 10 "goes into 2"  ZERO whole times, with two left over.  As a side note, you can also satisfy your curiosity by opening up Eclipse and actually *trying* it.  It's good practice using Eclipse, and you'll find out the answer for sure!    System.out.println(2 % 10);  // typed inside some class's main method
...