**New course!**Every coder should learn

**Generative AI!**

0

# Java 16.2 Task 4

Please copy the conditions of the task 4

7 Answers

+ 6

Please, share your attempt for further help.

+ 2

Thank you !

+ 1

Igaman Igaman
Your code is approximately correct.
Here is the correct solution. Initialise n with 1 not 3 and no need to check number > n
int n = 1;
while (n <= number) {
if(n % 3 == 0 || n % 10 == 3) {
System.out.println(n);
}
n++;
}

+ 1

Why 1???

+ 1

Igaman Igaman
Read problem statement again.
"prints all numbers from 1 to the inputted number"....

0

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner read = new Scanner(System.in);
int number = read.nextInt();
int n=1;
if(number>n)
{
while(n<=number)
{
if(n%3==0 || n%10==3)
System.out.println(n);
n++;
}
}
}
}

0

i ask people to share the terms of task 4