Passing arguments and returning values.

Posted by Unknown at 19:01

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!


Kindly Bookmark and Share it:

YOUR ADSENSE CODE GOES HERE

0 comments:

Have any question? Feel Free To Post Below:

 

© 2011. All Rights Reserved | Interview Questions | Template by Blogger Widgets

Home | About | Top