Skip to content

Q2 - Area of a Square

Compute and print the area of a square given its side.

package DSA.Practice_questions.VARIABLES_and_DATA_TYPES_QUESTIONS;
/*Question2:Inaprogram,inputthesideofasquare.Youhavetooutputtheareaofthesquare.(Hint : area of a square is (side x side)) */
import java.util.*;
public class question2 {
public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
System.out.println("Enter a Side of the square");
int side = sc.nextInt();
double square = side * side;
System.out.println(square);
} catch (Exception e) {
System.out.println(e);
}
}
}