Jump to content

This is java I need help writing this formula in my code I thin something is wrong with brackets

VoltaIsFuture
Go to solution Solved by shadowbyte,

you're going to want this

double finalScore = (Math.sqrt(Math.pow(x2 - x1, 2) +(Math.pow(y2 - y1, 2))));

 

double finalScore = (Math.sqrt)((Math.pow(y2-y1,2) + (Math.pow(x2-x2,2));

This is supposed to be the distance of a line formula cant get it to work because of brackets 

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Levisallanon said:

just count the amount of open and closed brackets and you'll find your problem.....
in the end you should have an equal amount ;).

Sorry but I am having a hard time understanding 

Link to comment
Share on other sites

Link to post
Share on other sites

you're going to want this

double finalScore = (Math.sqrt(Math.pow(x2 - x1, 2) +(Math.pow(y2 - y1, 2))));

 

Snorlax: i7 5820k @4.5ghz, Asus X99 Pro, 32gb Corsair Vengeance LPX 2666, Cryorig R1 Ultimate, Samsung 850 evo 500gb, Asus GTX 1080 ROG Strix, Corsair RM850x, NZXT H440, Hue+

Smallsnor: Huawei Matebook X

 

Canon AE-1 w/ 50mm f/1.8 lens

Pentax KM w/ 55mm f/1.8 SMC lens

Zenit-E w/ 58mm f/2 Helios lens

Panasonic G7 with 14-42mm f/3.5 lens

Polaroid Spectra System

 

Link to comment
Share on other sites

Link to post
Share on other sites

You need the same amount of )'s as you do ('s, otherwise you have brackets that are left open which will cause errors.

Just now, VoltaIsFuture said:

Sorry but I am having a hard time understanding 

 

PC - CPU Ryzen 5 1600 - GPU Power Color Radeon 5700XT- Motherboard Gigabyte GA-AB350 Gaming - RAM 16GB Corsair Vengeance RGB - Storage 525GB Crucial MX300 SSD + 120GB Kingston SSD   PSU Corsair CX750M - Cooling Stock - Case White NZXT S340

 

Peripherals - Mouse Logitech G502 Wireless - Keyboard Logitech G915 TKL  Headset Razer Kraken Pro V2's - Displays 2x Acer 24" GF246(1080p, 75hz, Freesync) Steering Wheel & Pedals Logitech G29 & Shifter

 

         

Link to comment
Share on other sites

Link to post
Share on other sites

if you would write the formula down normally it would be:
SQRT((x2-x1)²+(y2-y1)²)

so you want to keep these same brackets, but your programming language asks for some more.
The power ( ² ) is replaces by Math.pow(value,power) where in the first case value = (x2-x1) and the power = 2 so inserting that in the equation gives:
Math.pow((x2-x1),2)
so let's do it for the other one too
Math.pow((y2-y1),2)
now the sqrt in the main formula has to be replaced by Math.sqrt(value) so let's do that and insert the other things also:

Math.sqrt(Math.pow((x2-x1),2) + Math.pow((y2-y1),2) )

and that should be your equation.

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, Levisallanon said:

just count the amount of open and closed brackets and you'll find your problem....

People should be using an editor that does that for them.

Syntax checking has been around for a couple decades now.

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, geo3 said:

People should be using an editor that does that for them.

Syntax checking has been around for a couple decades now.

At school they tell me to use eclipse. So when I am at home I use Eclipse Oxygen. If you think there is an editor that I should use that is better for java coding, please let me know.

Link to comment
Share on other sites

Link to post
Share on other sites

32 minutes ago, VoltaIsFuture said:

At school they tell me to use eclipse. So when I am at home I use Eclipse Oxygen. If you think there is an editor that I should use that is better for java coding, please let me know.

Eclipse and Intellij are both good IDE's. They both offer syntax checking and completion so I would keep using Eclipse.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×