Breake after modulus | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Breake after modulus

So eventually i wanted learn how to find prime Numbers so i looked at the Code but did not understand this System out println(y) if(x%y==0) { break; } what is modulus in this case and why it breaks loop after printing that makes no sense i removed modulus statement and it started give me regular numbers Last thing how can i take number from loop to check it in another loop?

25th Mar 2018, 5:22 PM
TimeTraveler
TimeTraveler - avatar
4 Answers
+ 3
if (x%y) checks if x is divisible by y. For finding a prime number, you check if it is divisible by all numbers til itself. You don't have to check all numbers below y, just til it's square root. Hope you understood what I want to say.
25th Mar 2018, 5:41 PM
Jonas Schröter
Jonas Schröter - avatar
+ 2
So, if for example 39 is divisible by 13, it breaks the checking loop and goes on to the next number to check
25th Mar 2018, 5:41 PM
Jonas Schröter
Jonas Schröter - avatar
25th Mar 2018, 5:48 PM
Jonas Schröter
Jonas Schröter - avatar
+ 1
Thank you for support friend
25th Mar 2018, 5:48 PM
TimeTraveler
TimeTraveler - avatar