0

Why this code doesn’t print value ,,0”?

As in topic: import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); int number = read.nextInt(); //your code goes here for (int x=number; x>=0; x--){ if (x%3==0){ continue; }System.out.println(x); } } }

13th Jun 2021, 8:04 PM
Kamil Migdał
Kamil Migdał - avatar
4 ответов
+ 3
Just make sure x isn't equal to 0 in your if condition. if (x%3 == 0 && x != 0) { continue; }
13th Jun 2021, 8:27 PM
ChaoticDawg
ChaoticDawg - avatar
+ 2
Damn now thats looks soo eazy. I forgot about this solution. Thx so much ;)
13th Jun 2021, 8:28 PM
Kamil Migdał
Kamil Migdał - avatar
+ 1
Because 0%3 == 0 is true so the continue statement is ran and the loop moves on to the next iteration where x is reduced to -1 and the loop exits.
13th Jun 2021, 8:19 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Hm I understand now but how to solve it rn?
13th Jun 2021, 8:25 PM
Kamil Migdał
Kamil Migdał - avatar