FastFoodCoding

Login


Connect with one of the following accounts





Login

Please wait while we redirect...

Views: 1579   



Square is a parallelogram with four sides of equal length and with all right angles (90)
Following image shows you how a Square looks like

info-about-image

Following is the Java program that takes Length, Breadth as inputs and compute Area, Perimeter & Length of diagonal of a Square

import java.util.Scanner;

public class AreaAndPerimeterOfSquare {
    public static void main(String[] args) {

        // Taking inputs from user
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter the Length: ");
        double length = sc.nextDouble();

        sc.close();

        double area = length * length;
        double perimeter = 4 * length;
        double diagonal = Math.sqrt(2) * length;

        System.out.println("Area: " + area);
        System.out.println("Perimeter: " + perimeter);
        System.out.println("Length of diagonal: " + diagonal);

    }
}

Output

Enter the Length: 2
Area: 4.0
Perimeter: 8.0
Length of diagonal: 2.8284271247461903



On By


Top Tutorials

Top Questions

Top Articles

Top Blogs

Top News