mardi 13 août 2019

Java errors - my statement seems correct but I get the error else without it

I am trying to compile code for one of my lab exercises but I've checked it and still can't see what I'm doing wrong. Can anyone please see if anything is noticeably wrong?

Have tried changing order of braces, writing the expressions differently and rearranging the if else statements

{

    public static void main(String args[]) { //main method which calls leapYear and ... 
   leapYear(2019); // call method 
   leapYear(2020);
   leapYear(1900);
   leapYear(2000);
   leapYear(1565);

    }


    public static void leapYear(int year) { // Method which contains conditional statements that decide whether leap year is true/false


        if (year <= 1585) { // produces error statement if true 
        System.out.println(year + ":/t" + "Predates the Gregorian calendar");
        }


        else if (year % 4 = 0 (year % 100 = ! 0)) { // if year is divisible by 4 and only 4, may or may not be divisible by 400
        System.out.println(year + ":/t" + "is a leap year");
        }

        else if (year % 100 = 0 (year % 400 = 0)) { // if year is divisble by 400 and 100, but may or may not be divisible by 4 
        System.out.println(year + ":/t" + "is a leap year");
        }

        else {
        System.out.println(year + ":/t" + "is not a leap year"); // if all other statements are false, this one is executed

        }




        }

        }

I have 8 errors: "else without if", "not a statement" and "missing ;"

Aucun commentaire:

Enregistrer un commentaire