2
Write a program in Java to accept the diagonal of a square. Find and
display the area and perimeter by using Input stream.
Answers
Answered by
15
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
Social Sciences,
4 months ago
English,
4 months ago
Physics,
9 months ago
English,
1 year ago
English,
1 year ago