Monday, March 2, 2009

Structured Programming Example

class sample
{
/*A sample program to show how functions can be used*/
// Main Program
public static void main(String args[])
int year=1956;
//call function
if(leap_year(year))
System.out.println(year+" is a leap year");
else
System.out.println(year+" is not a leap year");
}
// Main Program Ends
//Function Begins
static boolean leap_year(int yr)
{
if(yr % 400== 0)
return true;
if(yr % 100== 0)
return false;
if(yr % 4== 0)
return true;
else
return false;
}
}

No comments:

Post a Comment