AREA OF CIRCLE, RECTANGLE,TRIANGLE USING FUNCTION OVERLOADING
import java.util.Scanner;
import java.lang.*;
class area
{
void
f(int x)
{
double
y=22.0/7.0*x*x;
System.out.println("area
of circle="+y);
}
void
f(int x,int y)
{
int
z=x*y;
System.out.println("area
of rectange="+z);
}
void
f(int x,inty,int z)
{
double
s=(x+y+z)/2;
double
s1=s*(s-x)*(s-y)*(s-z);
double
s2=Math.sqrt(s1);
System.out.println("area
of triangle="+s2);
}
}
class area1
{
public
static void main(String args[])
{
area
ob=new area();
ob.f(7);
// circle
ob.f(4,5);
// rectangle
ob.f(3,4,5);
// triangle
}
}
Output:E:\>javac area1.java
E:\>java area1
area of circle=154.0
area of rectangle=20
area of triangle=6.0
E:\>
No comments:
Post a Comment