math - Java Pythagorean Theorem -
import java.util.scanner; public class pythagoreantheorem { public static void main(string[] args) { // user input scanner keyboard = new scanner(system.in); double sidea, sideb, hypothenuse; system.out.println("please enter value of sidea"); sidea = keyboard.nextdouble(); system.out.println("please enter value of sideb"); sideb = keyboard.nextdouble(); // find value of hypothenuse hypothenuse = math.sqrt((sidea*sidea)+(sideb*sideb)); double roundoff = math.round( hypothenuse * 100) / 100; system.out.println("the length of hypothenuse " + roundoff ); } }
this code builds doesn't show general output. i'm trying display 2 decimals hypotenuse.
try use this:
double roundoff = math.round(hypothenuse * 100.0) / 100.0;
runing code has ex:
please enter value of sidea 232 please enter value of sideb 454 length of hypothenuse 509.84
Comments
Post a Comment