Dremendo Tag Line

Calculate area of a square in Java

Input - Question 11

In this question, we will see how to input side of a square in Java programming using the java input and find its area. To know more about java input click on the java input lesson.

Q11) Write a program in Java to input side of a square and find its area.

Formula: area = side * side

Program

import java.util.Scanner;

public class Q11
{
    public static void main(String args[])
    {
        int s,a;
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter side of a square ");
        s=sc.nextInt();
        a=s*s;
        System.out.print("Area=" + a);
    }
}

Output

Enter side of a square 5
Area=25
video-poster