Java Program to find area of Square

Get side of square and find area of square

Sample Input 1:

4

Sample Output 1:

16

Try your Solution

Strongly recommended to Solve it on your own, Don't directly go to the solution given below.

public class Hello { public static void main(String args[]) { //Write your code here } }

Program or Solution

				
			
					
import java.util.*;
class Square
{
 
       public static void main(String args[])
       {
 
            int side,area;
            Scanner sc=new Scanner(System.in);
            System.out.println("Get side of square and find area of square");
            System.out.println("Enter The Side:");
            side=sc.nextInt();
            area=side*side;
            System.out.println("The Output 1 Is:\n"+area);

        }

}
			
				
			

Program Explanation

Get side of a square (using scanner class) Calculate area by multiplying side and side(area = side * side) print area(using System.out.println())

Comments