Question

In: Computer Science

write a java program for area and perimeter of right triangle

write a java program for area and perimeter of right triangle

Solutions

Expert Solution

//RightTriangleAreaPerimeter.java
import java.util.Scanner;
public class RightTriangleAreaPerimeter {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        double base, height;
        System.out.print("Enter base of right angle triangle: ");
        base = scan.nextDouble();
        System.out.print("Enter height of right angle triangle: ");
        height = scan.nextDouble();

        double area = (base*height)/2;
        double perimeter = base+height+Math.sqrt(Math.pow(base,2)+Math.pow(height,2));

        System.out.println("Area = "+area);
        System.out.println("Perimeter = "+perimeter);
    }
}

​​​​​​​


Related Solutions

java create a class for triangle and also driver(area and perimeter) also write its getters and...
java create a class for triangle and also driver(area and perimeter) also write its getters and setters for the right triangle
In java. Prefer Bluej Create a program in java that calculates area and perimeter of a...
In java. Prefer Bluej Create a program in java that calculates area and perimeter of a square - use a class and test program to calculate the area and perimeter; assume length of square is 7 ft.
Create a program in java that calculates area and perimeter of a square - use a...
Create a program in java that calculates area and perimeter of a square - use a class and test program to calculate the area and perimeter; assume length of square is 7 ft.
Find a b c of a right triangle. with a perimeter of 18.
Find a b c of a right triangle. with a perimeter of 18.
The base of a right pyramid is an equilateral triangle of perimeter 8 cm and the height of the pyramid is 30√3 cm . Find the area and volume of the pyramid.
The base of a right pyramid is an equilateral triangle of perimeter 8 cm and the height of the pyramid is 30√3 cm . Find the area and volume of the pyramid.
Java Apply inheritance to write a super class and subclass to compute the triangle area and...
Java Apply inheritance to write a super class and subclass to compute the triangle area and the surface area of triangular pyramid, respectively. Assume that each side has the same length in the triangle and triangular pyramid. You need also to override toString() methods in both of super class and subclass so they will return the data of an triangle object and the data of the pyramid object, respectively. Code a driver class to test your classes by creating at...
You have to write a program that computes the area of a triangle. Input consists of...
You have to write a program that computes the area of a triangle. Input consists of the three points that represent the vertices of the triangle. Points are represented as Cartesian units i.e. X,Y coordinates as in (3,5). Output must be the three points, the three distances between vertices, and the area of the triangle formed by these points. The program must read the coordinates of each point, compute the distances between each pair of them and print these values....
5.11 LAB: Drawing a right triangle c++ This program will output a right triangle based on...
5.11 LAB: Drawing a right triangle c++ This program will output a right triangle based on user specified height triangleHeight and symbol triangleChar. (1) The given program outputs a fixed-height triangle using a * character. Modify the given program to output a right triangle that instead uses the user-specified triangleChar character. (1 pt) (2) Modify the program to use a nested loop to output a right triangle of height triangleHeight. The first line will have one user-specified character, such as...
Write a program to calculate the area of four shapes (Rectangle, triangle, circle and square). The...
Write a program to calculate the area of four shapes (Rectangle, triangle, circle and square). The program to present the user with a menu where one of the shapes can be selected. Based on the selection made, the user enters the proper input, the program validates the input (i.e all entries must be greater than zero). Once the input is entered and validated, the intended area is calculated and the entered information along with the area are displayed. Area of...
rite a program that will calculate the perimeter and area of a rectangle. Prompt the user...
rite a program that will calculate the perimeter and area of a rectangle. Prompt the user to input the length and width. Calculate the area as length * width. Calculate the perimeter as 2* length + 2* width. Display the area and perimeter. Please use a proper heading in a comment block (name, date, description of the program). Please use comments in your code. Run your program twice using different input. Copy the output and place it at the bottom...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT