Tuesday, 10 June 2014

Find area by taking their dimensions through command line argument.

class Area
{
      final double pi=3.14;
      void areaOfCircle(int r)
      {
          double area1=pi*r*r;
          System.out.println("area of circle="+area1);
       }
      void areaOfCylinder(int r,int h)
        {
          double area2=2*pi*r*(r+h);
          System.out.println("area of cylinder="+area2);
        }
    public static void main(String args[])
    {
int r1=Integer.parseInt(args[0]);
int h1=Integer.parseInt(args[1]);
           Area a = new Area();
           a.areaOfCircle(r1);
           a.areaOfCylinder(r1,h1);
    }
}

No comments:

Post a Comment