New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: Java

Triangle

15 Views
Copy Code Show/Hide Line Numbers
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

Add a comment


Report Abuse
brought to you by:
West Wind Techologies


If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate