Tuesday, 27 August 2013

Program that accepts a number as command line argument and display its square. If argument contains more than 1 number proper error message should be displayed.

public class Square {

    public static void main(String[] args) {
        if (args.length != 1)
        {
            System.out.println("Invalid argument");
            System.exit(0);

        }
        int num=Integer.parseInt(args[0]);
        System.out.println("Square of number is: "+num*num);



    }
}

No comments:

Post a Comment