- 1

Problem with task

Hi, can someone help me with this task : ,, 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 I think i don’t understand how loops can work . I know only how to txt program which prints 1,2,3,4,5 etc.

12th Jun 2021, 8:06 PM
Kamil MigdaƂ
Kamil MigdaƂ - avatar
5 RĂ©ponses
+ 3
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in); int number = input.nextInt(); int var = 1; while (var <= number) { if (var % 3 == 0 || var % 10 == 3) { System.out.println(var); } var++; } } } to solve any problems, you need to carefully study the topic
12th Jun 2021, 8:25 PM
SammE
SammE - avatar
+ 1
Hi! You pass lessons from 16.1 and so on?
12th Jun 2021, 8:25 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Thx a lot! When i tried it earlier i made mistake like this System.out.println(var); var++; } When correct code is } var++;
12th Jun 2021, 8:36 PM
Kamil MigdaƂ
Kamil MigdaƂ - avatar
+ 1
This little thing is not explained in the lesson :(
12th Jun 2021, 8:37 PM
Kamil MigdaƂ
Kamil MigdaƂ - avatar
+ 1
You can use for loop instead while
12th Jun 2021, 8:40 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar