Question #46279

Java programming.

Given that a Pythagoras theorem is

H2 =b2 +L2

Find h

Given that a Pythagoras theorem is

H2 =b2 +L2

Find h

Expert's answer

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

public class Pythagore {

public static void main(String[] args) {

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

double cat1 = 0, cat2 = 0;

System.out.print("The first cathetus: ");

try {

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

} catch (NumberFormatException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

System.out.print("The second cathetus: ");

try {

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

} catch (NumberFormatException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

System.out.println("The hypotenuse equals " + Math.sqrt(cat1*cat1 + cat2*cat2));

}

}

import java.io.IOException;

import java.io.InputStreamReader;

public class Pythagore {

public static void main(String[] args) {

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

double cat1 = 0, cat2 = 0;

System.out.print("The first cathetus: ");

try {

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

} catch (NumberFormatException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

System.out.print("The second cathetus: ");

try {

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

} catch (NumberFormatException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

System.out.println("The hypotenuse equals " + Math.sqrt(cat1*cat1 + cat2*cat2));

}

}

## Comments

## Leave a comment