+ 1

I want to print only prime nos. Plz check.(it's printing required output but 2 2 times)

https://code.sololearn.com/cYfhM1i4mFM1/?ref=app

17th Feb 2022, 4:09 AM
Sonali Kala
Sonali Kala - avatar
7 Respuestas
+ 1
Flag is always false...I do litle changes to your code, check it here:https://code.sololearn.com/cf0Jx2cbE4f3/?ref=app
17th Feb 2022, 4:22 AM
Cristian Baeza Jimenez
Cristian Baeza Jimenez - avatar
+ 1
I got the same as Cristian Baeza Jimenez by changing the print line to be if (i==num) System.out.println(num); I didn't mess about with your unused flag.
17th Feb 2022, 4:49 AM
HungryTradie
HungryTradie - avatar
+ 1
Sure mate, I literally only changed that line.. Edit: hold up, it doesn't work correctly!!! sorry. EDIT2: fixed it, used the flag, moved the assignment of num, only check factors to half of i. Do you see what I changed, and why?? https://code.sololearn.com/cHEG95rOFGwN/?ref=app
17th Feb 2022, 6:04 AM
HungryTradie
HungryTradie - avatar
+ 1
17th Feb 2022, 7:07 AM
Sonali Kala
Sonali Kala - avatar
17th Feb 2022, 4:30 AM
Sonali Kala
Sonali Kala - avatar
0
HungryTradie can u share u soln plz.
17th Feb 2022, 5:17 AM
Sonali Kala
Sonali Kala - avatar
0
Here another code originally from @GUMPERT https://code.sololearn.com/cWqsvh2kOTU4/?ref=app
19th Feb 2022, 1:22 AM
Cristian Baeza Jimenez
Cristian Baeza Jimenez - avatar