+ 3

[HELP] no more threes practice JAVA

Hey I stuck w/ this code ... it doesn’t print out the 0 in none of the 5 test cases.. Where is my mistake Thank you so much import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); int num = read.nextInt(); //your code goes here for (int x = 0; x <= num-1; num--){ if (num % 3 != 0){ System.out.println(num); } } } }

24th Jan 2021, 6:45 PM
zer0x0
zer0x0 - avatar
4 odpowiedzi
+ 8
zer0x0 You have to change loop and if condition like this for (int x = num; x >= 0; x--) { if (x == 0 || x % 3 != 0) { System.out.println(x); } }
24th Jan 2021, 7:41 PM
A͢J
A͢J - avatar
+ 3
It will not print out 0 because 0 is divisible by 3
24th Jan 2021, 7:02 PM
Indranil
Indranil - avatar
+ 1
/*Your code is Correct bro.Same Mistake Was With me But then Suddenly an idea came up in mind to manually Print 0 outside the loop so it automatically prints zero after the loop breaks like this:*/ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); int num = read.nextInt(); //your code goes here for (int x = 0; x <= num-1; num--){ if (num % 3 != 0){ System.out.println(num); } } System.out.println ("0"); } } //Try it it will definetely work. Inshallah
2nd May 2021, 8:09 AM
Arham Khan
0
Indranil Bhadra any suggestions how to change the if statement
24th Jan 2021, 7:25 PM
zer0x0
zer0x0 - avatar