Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PROGRAM TO FIND AREA OF DIFFERENT SHAPES USING OVERLOADING
#1

Code:
import java.io.*;
class Area
{
void area(int l,int b)
{
int ar=l*b;
  System.out.println("Area of rectangle="+ar);
}
void area(double r,double h)
{
double ar=(3.14*r*r*h);
  System.out.println("Area of circle="+ar);
}
void area(int a)
{
int ar=a*a;
System.out.println("Area of square="+ar);
}
void area(float b,float h)
{
double ar=0.5*b*h;
System.out.println("Area of triangle="+ar);
}
}

class Newar
{
public static void main(String args[])throws IOException
{
Area r=new Area();
DataInputStream dis=new DataInputStream(System.in);
System.out.println("enter length");
int i=Integer.parseInt(dis.readLine());
System.out.println("enter breadth");
Int j=Integer.parseInt(dis.readLine());
r.area(i,j);
System.out.println("enter radius");
double k=Double.parseDouble(dis.readLine());  
System.out.println("enter height");  
double l=Double.parseDouble(dis.readLine());
  r.area(k,l);
System.out.println("enter the length of one side");
int m=Integer.parseInt(dis.readLine());
r.area(m);
System.out.println("enter base");
float n=Float.parseFloat(dis.readLine());  
System.out.println("enter height");  
float o=Float.parseFloat(dis.readLine());
r.area(n,o);
}
}

OUTPUT
E:\ 5BCA-B\lijo\java >java Newar
enter length
2
enter breadth
2
Area of rectangle=4
enter radius
2
enter height
2
Area of circle=25.12
enter the length of one side
2
Area of square=4
enter base
2
enter height
2
Area of triangle=2.0
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

Powered By MyBB, © 2002-2024 iAndrew & Melroy van den Berg.