Thursday, 13 June 2013

square of given number in java

import java.io.*;
class simple_square2
{
    public static void main(String args[])
    {
        try
        {
            int a,c;
            DataInputStream cin=new DataInputStream(System.in);
            System.out.println("Enter a number to calculate its square");
            a=Integer.parseInt(cin.readLine());
            c=a*a;
            System.out.println("square of given "+a+" number is = "+c);
        }
        catch(Exception e)
        {
            System.out.println("Wrong data");
        }
    }
}

No comments: