This site requires JavaScript, please enable it in your browser!
Greenfoot back
thefutureisnow
thefutureisnow wrote ...

2012/4/28

Equations

thefutureisnow thefutureisnow

2012/4/28

#
I'm trying to make an object move according to an equation with exponents. The code I tried using is similar to what is below: 'setLocation(getX()+1, (getX()+1)^2);' When I compiled it and ran it, the object didn't move using the exponent. Is there a certain method or command I need to use before starting an equation?
danpost danpost

2012/4/28

#
You might want to check out the Java tutorials and APIs on the oracle site; but, for now, just use (getX() + 1) * (getX() + 1)
thefutureisnow thefutureisnow

2012/4/28

#
Dang, well, thanks. You seem to be replying to all my questions :).
danpost danpost

2012/4/29

#
Java tutorials and API links is the home page of what I was referring to. The best place to start would probably be in the second section of the left labelled in red: 'Trails Covering the Basics'; and it is probably best to go through each one (eventually), but at least the first two to start. In the third boxed-in section on the right, you will see the link to the 'API documentation'. The main package to look at is the 'Java.lang' package; and for you question above, see the 'Math' class within that package.
nccb nccb

2012/4/29

#
The ^ operator is actually exclusive-or in Java, I believe (it's quite rare). Either spell out the square as danpost says, or use Math.pow(getX() + 1, 2).
thefutureisnow thefutureisnow

2012/4/29

#
I found the solution for it, I use the java.lang.Math library, it contains a lot of mathematical operators that you normally can't use. Thanks guys!
danpost danpost

2012/4/30

#
Actually, you can use those commands anytime, without having to specify 'import java.lang.Math;', being it is part of the java.lang package.
You need to login to post a reply.