0

I am at a loss for while loops

A client wants you to write a program that prints all numbers from 1 to the inputted number that are either a multiplier of 3 or end with 3. Sample input 14 Sample output 3 6 9 12 13 So far I did while ( number % 3 == 0 || number % 10 == 3) { System.out.println(number) number++; } I got the hidden question right but in the other cases I am only receiving one output.

14th Mar 2021, 5:06 AM
Karina Matlock
Karina Matlock - avatar
4 Answers
+ 4
Karina Matlock You have to declared a new variable with 1 which will check condition like while (variable <= number) { if (variable % 3 == 0 || variable % 10 == 3) { //print variable } variable++; } https://code.sololearn.com/cj1g78MXa1gf/?ref=app
14th Mar 2021, 5:59 AM
A͢J
A͢J - avatar
+ 1
Karina Matlock Just change (var < number) to (var <= number) then it will work.
14th Mar 2021, 8:05 AM
A͢J
A͢J - avatar
+ 1
I finally got it. Thank you!
15th Mar 2021, 3:10 PM
Karina Matlock
Karina Matlock - avatar
0
Its not working for me
14th Mar 2021, 7:48 AM
Karina Matlock
Karina Matlock - avatar