Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

1. ## User-Defined Methods

I am writing a program for my Java class that takes the length of two sides of a right triangle, and calculates the hypotenuse, as well as the sine, cosine, and tangent of each non-right angle of the right triangle. The calculations for the hypotenuse, sine, cosine, and tangent should be placed in separate methods.
I keep getting two errors when I try to declare my methods, 'class' expected and ')' expected. I cannot figure out what I am doing wrong, any help would be appreciated.

```import java.util.*;
import static java.lang.Math.*;

public class RightTriangle
{

public static void main(String[] args)
{

double a, b, c;

+ " of side of the triangle", a);
a = console.nextDouble();
System.out.println("The opposite side of the"
+ "triangle is ", a);

+ " of side of the triangle", b);
b = console.nextDouble();
+ "trianlge is ", b);

c =((a*a) + (b*b));
hypotenuse = c*c;
System.out.println("The hypotenuse of the triangle"
+ "is ", hypotenuse);

sine(double a, double c);

cosine(double b, double c);

tangent(double b, double c);

}

public static double getSine(double a, double c)
{
double opp;
double hyp;

opp = a.getNum();
hyp = c.getNum();

sine = opp/hyp;
System.out.println("The sine of the triangle"
+ "is ", sine);
}

public static double getCosine(double b, double c)
{
double hyp;

hyp = c.getNum();

System.out.println("The cosine of the triangle"
+ "is ", cosine);
}

public static double getTangent(double a, double b)
{
double opp;

opp = a.getNum();

tangent = a/b;
System.out.println("The tangent of the triangle"
+ "is ", tangent);
}

}```  Reply With Quote

3. ## Re: User-Defined Methods

```String s = "hello world";
System.out.println(String s);```
What is wrong with the above code?  Reply With Quote

4. ## Re: User-Defined Methods

Once you solve that riddle you have numerous other problems with your code.  Reply With Quote

5. ## Re: User-Defined Methods Originally Posted by Junky ```String s = "hello world";
System.out.println(String s);```
What is wrong with the above code?
System.out.println(s);  Reply With Quote

6. ## Re: User-Defined Methods

Congratulations but the question was aimed at ZippyShannon so they can work out for themselves what is wrong with their code.  Reply With Quote