+ 1

Me again. Still doesn't really work.

Do While Loops Write a program that takes N numbers as input and outputs the numbers from N to 0, skipping the ones that are multiple of 3. Sample Input 7 Sample Output 7 5 4 2 1 0 My code: import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); int number = read.nextInt(); // N while(number > 0) { if(number%3==0) { continue; } System.out.println(number); number = number - 1; } System.out.println("0"); } } What is still wrong ? My output is : Execution Timed Out!

23rd Aug 2021, 1:36 PM
Lisa Kraack
Lisa Kraack - avatar
5 odpowiedzi
+ 5
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); int number = read.nextInt(); // N while(number>0) { if (number%3==0){ number = number - 1; continue; } System.out.println(number); number = number - 1; } System.out.println("0"); read.close(); } }
23rd Aug 2021, 1:49 PM
Edwin
Edwin - avatar
+ 3
//it goes infinite after number%3 condition because you need to decrement it
23rd Aug 2021, 1:50 PM
Edwin
Edwin - avatar
+ 1
Thank you so much, Edwin. You helped me a lot.
23rd Aug 2021, 1:53 PM
Lisa Kraack
Lisa Kraack - avatar
+ 1
Lisa Kraack you're welcome.
23rd Aug 2021, 2:04 PM
Edwin
Edwin - avatar
+ 1
Please remember to put your code in a playground script and link it here – that way it is easier to read and easier to test if necessary! :)
23rd Aug 2021, 2:32 PM
Lisa
Lisa - avatar