I'm writing a program that calculates the hypotenuse of a triangle, and I'm supposed to call up a method into the main.
Is it better to have them in 2 separate files, or to have the method I'm calling up in the program I'm running?
In the program, I keep getting error messages about the last line of code, with the JOptionPane output.
What am I getting wrong?
import javax.swing.JOptionPane;
import java.util.Scanner;
public class A2
{
public static double Hypo(double a,double b,double c);
double a,b,c;
{
hyp=((a*a)+(b*b));
c=Math.sqrt(hyp);
}
int x,y;
double c;
String text1=JOptionPane.showInputDialog("How long is side A? ");
int x=Integer.parseInt(text1);
String text2=JOptionPanes.howInputDialog("How long is side B? ");
int y=Integer.parseInt(text2);
double c=A2.Hypo(x,y);
JOptionPane.showMessageDialog(null, "The hypotenuse of the triangle is " +c);
}
This code has so many problems it's hard to know where to begin.
Here's some advice:
Start with this. It runs and gives correct results: