Language: Java
Triangle
package righttriangle; import java.util.Scanner; import java.util.Random; public class Triangle { public static void main(String[] args) { double side1, side2; double hypotenuse; Scanner scan = new Scanner( System.in ); Random rnd = new Random(); System.out.print( "Enter lengths of the sides: " ); side1 = scan.nextDouble(); side2 = scan.nextDouble(); // Pytagoras sats: c^2 = a^2 + b^2 // Hypotenusan (c) blir då c = sqrt(a^2 + b^2) hypotenuse = Math.sqrt( (side1 * side1) + (side1 * side2) ); System.out.println( "Length of the hypotenuse: " + hypotenuse ); // Slumpmässigt.. side1 = rnd.nextInt(20); side2 = rnd.nextInt(20); hypotenuse = Math.sqrt( (side1 * side1) + (side1 * side2) ); System.out.println( "Length of the hypotenuse: " + hypotenuse ); } }
by
February 08, 2010 @ 12:43pm
February 08, 2010 @ 12:43pm
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search

