Computer Science, asked by swathasingh, 4 months ago

wap a java program please​

Attachments:

Answers

Answered by anindyaadhikari13
3

Required Answer:-

Question:

  • Write a program in Java to enter the side of a square and display the area and diagon using Math functions.

Solution:

Here is the program.

import java.util.*;

public class Square {

public static void main(String[] args) {

double s, a, d;

Scanner sc=new Scanner(System.in);

System.out.print("Enter the side: ");

s=sc.nextDouble();

sc.close();

a=Math.pow(s, 2);

d=Math.sqrt(2)*s;

System.out.println("Area: "+a);

System.out.println("Diagonal: "+d);

}

}

Explanation:

  • We will ask the user to enter the side. Then, using formula, we will calculate the area and diagonal of the square and display the result on the screen.

Output is attached.

Attachments:
Similar questions