Java Function which prints square of given number.

//Java Function which prints square of given number.

import java.util.Scanner;

public class Program 
{   
    	public static void main( String[] args ) 
    	{
		Scanner reader = new Scanner(System.in);
		int a,ans;
		System.out.print("Enter a digit to find square : ");
		a = reader.nextInt();
		ans=sqr(a);
		System.out.print("\n\nSquare of "+ a +" : "+ ans +"");
    	}

    	public static int sqr(int a)
    	{
		int ans;
		ans=a*a;
		return ans;
     	}
}

Output :
Enter a digit to find square : 5

Square of 5 : 25



Leave a comment