Computer Science, asked by Samsharma68271, 4 months ago

Write an algorithm ,draw a flowchart and write a java program in the following specifications:
1 ) find the area of triangle after taking height and base as input

Answers

Answered by matteodagostino
0

import java.util.Scanner; // Imports the Scanner class to ask user for input

public class AreaOfTriangle {

 

public static void main(String[] args) {

 

 Scanner input = new Scanner(System.in); // Creates a scanner called "input"

 

 System.out.print("Enter the height of the triangle in centimetres: "); // Asks the user for the height of the triangle

 double height = input.nextDouble(); // Stores the user's answer in a variable called height

 

 System.out.print("Enter the base of the triangle in centimetres: "); // Asks the user for the base of the triangle

 double base = input.nextDouble(); // Stores the user's answer in a variable called base

 

 double area; // Creates variable called area which will store the final answer

 

 area = (height * base)/2; // Finds the area of the triangle

 

 System.out.println("The area of the triangle is " + area + " cm^2"); // Prints the answer

   

}

}

Similar questions