+ 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); } } } }
4 Respuestas
+ 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);
}
}
+ 3
It will not print out 0 because 0 is divisible by 3
+ 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
0
Indranil Bhadra any suggestions how to change the if statement