Question #46278

Java programming.

Find the area of a triangle

Area =1/2base x height

Find the area of a triangle

Area =1/2base x height

Expert's answer

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

public class Triangle {

public static void main(String[] args) {

BufferedReader buffRead = new BufferedReader(new InputStreamReader(System.in));

double base = 0, height = 0;

System.out.print("Enter base: ");

try {

base = Double.parseDouble(buffRead.readLine());

} catch (NumberFormatException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

System.out.print("Enter height: ");

try {

height = Double.parseDouble(buffRead.readLine());

} catch (NumberFormatException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

System.out.println("Area equals " + 0.5*base*height);

}

}

import java.io.IOException;

import java.io.InputStreamReader;

public class Triangle {

public static void main(String[] args) {

BufferedReader buffRead = new BufferedReader(new InputStreamReader(System.in));

double base = 0, height = 0;

System.out.print("Enter base: ");

try {

base = Double.parseDouble(buffRead.readLine());

} catch (NumberFormatException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

System.out.print("Enter height: ");

try {

height = Double.parseDouble(buffRead.readLine());

} catch (NumberFormatException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

System.out.println("Area equals " + 0.5*base*height);

}

}

## Comments

## Leave a comment