I try to run but I don't can.

write a Java Program that calculates the length of a hypotenuse of a right
triangle.the method should take two arguments of the double and return the hypotenuse as double.

import java.io.*;

public class Hypotenuse

public static void main(String[] args)
double hypotenuse;
double length;
String side1;
String side2;

/** @attribute System.STAThread() */
public static void main(String[] args)
throws java.io.IOException

InputStreamReader isr = new InputStreamReader(System.in);

BufferedReader input = new  BufferedReader(isr);
double result
System.out.print("Enter the first side of the triangle: ");
String side1 = input.readLine();
double side1 = Double.parseDouble(side1);

double result;
System.out.print("Enter the second side of the triangle: ");

String side2 = input.readLine();
double side2 = Double.parseDouble(side2);

// TODO: Add code to start application here

result = hypotenuse ( side1, side2 );
System.Out.println("Hypotenuse of your triangle is: " + result );
return 0;


You have two public static void mains. NO no no...!

You using buffered input from the command line. Since that is non-standard it's hard to tell if there might be a problem there?

Also, where oh where, is your actual calculation for the length of the hypotenuse. Hmm? There should be a squareroot sumwhere...

God bless.


This article has been dead for over six months. Start a new discussion instead.