Results 1 to 3 of 3
  1. #1
    fsuarjun03 is offline Member
    Join Date
    Mar 2010
    Posts
    13
    Rep Power
    0

    Default converting an algebraic equation to Java

    How do I go about converting the Pythagorean Theorem into Java?

    is it a little like this? I'm just lost on how to get put square root into that formula. What is the proper way to do it?


    z = (x * x) + (y * y)

  2. #2
    StormyWaters is offline Senior Member
    Join Date
    Feb 2009
    Posts
    307
    Rep Power
    6

    Default

    Check out this class

    Math (Java 2 Platform SE v1.4.2)

  3. #3
    fsuarjun03 is offline Member
    Join Date
    Mar 2010
    Posts
    13
    Rep Power
    0

    Default

    Ahhh. That helps a bit but how do I put it all together.


    I am trying to create a class to solve for all parts of Pythagoreans Theorem. I am starting with solving for the sides and then moving on to solving for the angles. I'm just going to show you what I have so far. I know its not right but here.

    Java Code:
    public class Pythagoras
    {
        private int x, y, z;
        public Pythagoras(int x, int y, int z)
        {
                x = (int) 1;
                y = (int) 1;
                z = (int) 1;
        }
        public void calculate()
        {
            z = ((x * x) + (y * y));
            x = ((z * z) - (y * y));
            y = ((z * z) - (x * x));
        }
        public int getSideX()
        {
            return x;
        }
        public int getSideY()
        {
            return y;
        }
        public int getSideZ()
        {
            return z;
        }
    }
    Where should the following go in the above section? Does it go in there or should it be in the Test Class?

    Java Code:
    public static double sqrt(double a)
    I am a newbie and I'm trying to teach myself. I joined the forum because I figured that all you guys know a lot of Java and I could learn from all the problems that everyone else comes across and maybe even get to the point where I could help other people.

Similar Threads

  1. Need help with math equation
    By annabellastorm in forum New To Java
    Replies: 4
    Last Post: 01-10-2010, 06:12 PM
  2. differential equation RK4
    By arvindmer in forum New To Java
    Replies: 3
    Last Post: 01-08-2009, 02:27 PM
  3. Quadratic Equation
    By jpnym15 in forum New To Java
    Replies: 4
    Last Post: 11-12-2008, 04:29 AM
  4. Help with an equation in java
    By coco in forum New To Java
    Replies: 1
    Last Post: 07-31-2007, 08:47 AM
  5. Help with quadratic equation in java
    By paul in forum New To Java
    Replies: 1
    Last Post: 07-25-2007, 09:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •