wap a java program please
Attachments:
Answers
Answered by
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
Accountancy,
1 month ago
English,
1 month ago
Biology,
3 months ago
India Languages,
9 months ago
Math,
9 months ago
English,
9 months ago