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.

## Wednesday, March 17, 2010

Subscribe to:
Post Comments (Atom)

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

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

ReplyDeleteI am quite a lot confused with ur reply.....couldnt just easily type it in.....

ReplyDeleteclass Pascal

ReplyDelete{

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(" ");

}

}

}