Question 9

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);

}

}

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

1 Like

Could you give it another try now please?

It works well now, thank you.

2 Likes

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

5 % 3 = 1.66666667

14 % 7 = 2
30 % 15 = 2

Please explain the math to me.

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

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

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?

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

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!

1 Like

6 % 14= 2;
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh

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

int myRemainder = 14 % 6;

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

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

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

Oh… I was thinking about round up…

Thank you for your time. #URthebest

1 Like