+ 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?
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.
+ 2
So, if for example 39 is divisible by 13, it breaks the checking loop and goes on to the next number to check
+ 1
+ 1
Thank you for support friend