Project Euler problem #19: counting months that began on Sundays
int day = 4; // Lets number the days of week from 1:7 &amp;&amp; Sunday is the first day;;; note : 1 jan 1901 was Tue day



The comment gets lost on the right edge of this narrow screen.

The position of the comment implies that it is specific to the variable day, but that's not true of the first sentence.

For working with % it would be less confusing to use 0 to 6 rather than 1 to 7.

Given that day = 4, why does the comment tell us that 1 jan 1901 was Tue day? What does day represent here? If it's 1900-12-01 then the comment should talk about that date. In general, day is not a self-explanatory name.




            for(int mon = 1; mon &lt;= 12; mon++) {



mon for Monday? Again, not the most helpful name.




                day += days(mon, year);
                if(day%7 == 1)
                    sundays++;



Is overflow of day a risk?




    public static int days(int num, int year) {
        int res = 0;
        int feb = 28;
        if(isLeapYear(year))
            feb = 29;
        switch(num) {
            case 1 : res = 31; break;
            case 2 : res = feb; break;
            ...
            case 12 : res = 31; break;
        }
        return res;
    }



num? That's completely uninformative. I know it's a number because I can see that its type is int.

Early returns would make this shorter and more obviously correct:

        switch (month) {
            case 1 : return 31;
            case 2 : return isLeapYear(year) ? 29 : 28;
            ...


It's bad practice to have a switch without a default, even if the only thing the default does is throw new Exception("This should be unreachable code").

One option would be to group the cases according to a well-known rhyme, and pull the sanity checking out of the switch:

        if (month &lt; 1 || month &gt; 12) throw new IllegalArgumentException("month");

        switch (month) {
            // 30 days have September, April, June and November...
            case 9:
            case 4:
            case 6:
            case 11:
                return 30;

            // ... All the rest have 31 ...
            default:
                return 31;

            // ... except for February alone.
            case 2:
                return isLeapYear(year) ? 29 : 28;
        }





    public static boolean isLeapYear(int year) {
        if(year%4 == 0) 
            if(year%100 == 0) {
                if(year%400 == 0)
                    return true;
            } else
                return true;
        return false;
    }



Simplifying from the inside out, and putting in the necessary {} to be sure that the code does what we expect, we get:

    public static boolean isLeapYear(int year) {
        if (year % 4 == 0) {
            if (year % 100 == 0) {
                return year % 400 == 0;
            }
            return true;
        }
        return false;
    }




    public static boolean isLeapYear(int year) {
        if (year % 4 == 0) {
            return y % 100 &gt; 0 || year % 400 == 0;
        }
        return false;
    }




    public static boolean isLeapYear(int year) {
        return year % 4 == 0 &amp;&amp; (y % 100 &gt; 0 || year % 400 == 0);
    }




    public static boolean isLeapYear(int year) {
        return (year % 4 == 0 &amp;&amp; y % 100 &gt; 0) || year % 400 == 0;
    }


Of course, given that we're only interested in years 1901 to 2000, this could be simplified further.