- 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.
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
+ 1
Hi! You pass lessons from 16.1 and so on?
+ 1
Thx a lot! When i tried it earlier i made mistake like this
System.out.println(var);
var++;
}
When correct code is
}
var++;
+ 1
This little thing is not explained in the lesson :(
+ 1
You can use for loop instead while