Search This Blog

Wednesday, March 17, 2010

Q.Enter a year and test whether it is a leap year or not, shorter way.....

Ans.

public class LeapYearAnother
{
public boolean isLeapYear(int year)
{
return((year%4==0) && (year%100!=0) || (year%400==0))?true:false;
}
}








Discussing Java application programming across the barrier of classroom for the young minds.

4 comments:

  1. Well sir....could u plz blog in a smarter way to compile the pascal's triangle prog/?????

    ReplyDelete
  2. Fine. To save time just write what "unsmart way" you already know(just the logic not the program). shall eliminate that/them from consideration.

    ReplyDelete
  3. I am quite a lot confused with ur reply.....couldnt just easily type it in.....

    ReplyDelete
  4. class Pascal
    {
    double fact(double n)
    {

    return (n > 1) ? n * fact(n - 1) : 1;

    }
    double ncr(int n, int r)
    {

    return fact(n) / (fact(r) * fact(n - r));

    }
    void generate()
    {
    for (int i = 0; i < 15; i++)
    {
    for (int j = 0; j <= i; j++)
    {
    System.out.print((int)ncr(i, j));
    }
    System.out.println(" ");
    }
    }
    }

    ReplyDelete