Ads Top

Program for passing arguments to method using java

Program ,passing arguments to method, java,lab,practical,computer

program to calculate area and perimeter of the circle


program

import java.io.dataInputStream;
class circle
{
float area(float rad)
{
return(3.14*rad*rad);
}
float perimeter(float rad)
{
return(3.14*2.0f*rad);
}
}
public class circlearea
{
public static oid main(String args[])
{
float farea,fradius,fperimeter;
DataInputStream did=new DataInputStream(System.in);
circle objcircle=new circle();
try
{
Syste.out.println("Ente the radius");
fradius=float,valueOf(did.readLine());
farea=objcircle.area(fradius);
fperimeter=objcircle.objcircle.perimeter(fradius);
System.out.println("Area of circle:"+farea);
System.out.println("Perimeter of circle:"+fperimeter);
}
catch(Exception e)
{
System.out.println("Error");
}
}
}

Output

Enter the radius:2.0
Area of circle:12.56
Perimeter of circle:1256

No comments:

Touchfeeds. Powered by Blogger.