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.
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
+ 1
Karina Matlock
Just change (var < number) to (var <= number) then it will work.
+ 1
I finally got it. Thank you!
0
Its not working for me