Java Practical 7:
/*Create a method area(),overload it to calculate area of Circle,Rectangle & Square.*/
class Overload
{
void area(float x)
{
System.out.println("the area of the square is "+Math.pow(x, 2)+" sq units");
}
void area(float x, float y)
{
System.out.println("the area of the rectangle is "+x*y+" sq units");
}
void area(double x)
{
double z = 3.14 * x * x;
System.out.println("the area of the circle is "+z+" sq units");
}
public static void main(String args[])
{
area(5);
area(11,12);
area(2.5);
}
}
class Overload
{
void area(float x)
{
System.out.println("the area of the square is "+Math.pow(x, 2)+" sq units");
}
void area(float x, float y)
{
System.out.println("the area of the rectangle is "+x*y+" sq units");
}
void area(double x)
{
double z = 3.14 * x * x;
System.out.println("the area of the circle is "+z+" sq units");
}
public static void main(String args[])
{
area(5);
area(11,12);
area(2.5);
}
}
Comments
Post a Comment