I can´t print out 0 . Can someone tell me why?

Viewed 63

I can´t print out 0 . Can someone tell me why?

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner read = new Scanner(System.in);
        System.out.print("Number: ");
        int number = read.nextInt();
        //your code goes here
        while (number >= 0) {
            if(number % 3 == 0) {
                number--;
                continue;
            }
            System.out.println(number);
            number--;
        }
    }
}
1 Answers

You continue passed the 0 and never output it:

if(number % 3 == 0) {
   number--;
   continue;
}

0 % 3 == 0 // TRUE

You will need to have special handling for the 0 case with the logic you have currently. I will leave it for you to figure that part out.

Related