Passing arguments and
returning values.
class
circle
{
private int radius;
public void setradius(int r)
{
radius = r;
}
public float calculate()
{
return 3.14f * radius * radius;
}
public static void main(String args[])
{
if (args.length < 1)
{
System.out.println("Invalid Arguments");
System.exit(0);
}
circle c = new circle();
c.setradius(Integer.parseInt(args[0]));
float area = c.calculate();
System.out.println("Radius
: " + args[0]);
System.out.println("Area :
" + area);
}
}
If you enjoyed this post and wish to be informed whenever a new post is published, then make sure you subscribe to my regular Email Updates. Subscribe Now!
0 comments:
Have any question? Feel Free To Post Below: