dimanche 9 septembre 2018

How to make an if not equals to statement in Java

I'm currently trying to run a method that takes a user inputted year and then divides the inputted year by 4, 100 & 400 respectively.

        public void printLeapYear() {

    if (year % 4 == 0) {
        System.out.println("The year " + year + " is a common year");
    }
    else if (year % 100 == 0) {
        System.out.println("The year " + year + " is a leap year");
    }
    else if (year % 400 == 0) {
        System.out.println("The year " + year + " is a common year");
    }
    else {
        System.out.println("The year " + year + " is a leap year");
    }

}

However, I don't want Java to check if the year is equal to the division, I want java to check if it is not. I'm very new to programming and have tried

if (year != year % 4 == 0) {
        System.out.println("The year " + year + " is a common year");
    }

but I get an incompatible Boolean and int error message.

Thank you!

Aucun commentaire:

Enregistrer un commentaire