Pythagoras

From CompSciWiki
Revision as of 12:33, 6 April 2010 by TimC (Talk | contribs)

Jump to: navigation, search

Back to the Program-A-Day homepage

Problem

Create a program that will allow the user to enter in the lengths of two sides of a right-angled triangle, and will output the length of the triangle's hypotenuse. The two sides should be entered using two consecutive JOptionPane.showInputDialog boxes, and the result should be given using System.out.println. The input should be taken as two positive decimal values. Assume valid inputs.

The formula for calculating the hypotenuse is <math>a^2 + b^2 = c^2</math>, where a and b are the two sides, and c is the hypotenuse.

To solve this problem, you will need to understand:

Sample Input: 3,4 Sample Output: 5.0

Sample Input: 2.5,2.5 Sample Output: 3.5355339059327378

 

SideSectionTitle

Wiki chars03.jpg


Solution

The solution...

For the entire code solution, see below.

Code

Solution Code

Back to the Program-A-Day homepage