Computer Science, asked by varunkeswani41, 8 months ago

Write a in JAVA program to calculate perimeter and diagonal of a square. Take
side as an input.

Answers

Answered by bharath0503005
5

Answer:

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.82842712474619

Answered by Anonymous
0

Answer:

Output

Enter the Length: 2

Area: 4.0

Perimeter: 8.0

Length of diagonal: 2.82842712474619

Explanation:

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);

}

}

Similar questions