Question 9


#1

For some reason the modulo question doesn't seem to be working, here is the code, but it does return "2", and the answer asks for you to do just this.

public class Modulo {
public static void main(String[] args) {

	int myRemainder = 5 % 3;
	System.out.println(myRemainder);

}

}


#2

It's a new, bug -- lots of us have reported it already -- but go ahead and use the Bug Report link too!


#3

Could you give it another try now please?


#4

It works well now, thank you.


#5

Wait...Im confused. How is 5 % 3 = 2 ??

5 % 3 = 1.66666667

14 % 7 = 2
30 % 15 = 2

Please explain the math to me.


#6

3 goes into 5 one time, with a remainder of 2. The modulo is used to get remainders, as is explained in the lesson.


#7

So 14 % 12 = 2, and 30 % 28 = 2


#8

But why doesn't it work when you try to mimic the instructions? 15 % 6 apparently returns 3 because after 6 goes into 15 twice, 3 is the remainder. But when I tried 14 % 6 or 8 % 3, it wouldn't return 2. It only seemed to work when the second number could only go into the first number once. Why is this?


#9

It returns 2 for me, what did it return for you? Could we get a screenshot?


#10

Just tried to replicate it, but it's working now. I'm wondering if I didn't close the line with a semi-colon.

Thank you for your response, though!


#11

6 % 14= 2;
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh


#12

it still doesn't work, it trind 14%6=2 and your numbers but it still doesn't work.


#13
int myRemainder = 14 % 6;

#14

I wonder if it does work with 3 % 2, because its remainder could be 2 too. hmmm..?
I am very beginner with it. So, anyone can explain easily? Thanks


#15

No problem. It would not work with 3 % 2 because the remainder is 1.

3 / 2 = 1 remainder 1
3 % 2 = 1

#16

Oh... I was thinking about round up...

Thank you for your time. #URthebest