posted 8 months ago

The minimum runway length for this airplane is 514.286

This is my code

Enter speed and acceleration: 60 3.5

The minimum runway length for this airplane is 6300.0

Question: Write a program that prompts the user to enter v in meters/second(m/s) and the accelearation a in (m/s^2) and display the length by using formula

length = v^2/2a

**Expected Output**

Enter speed and acceleration : 60 3.5

The minimum runway length for this airplane is 514.286

This is my code

But I get this output

But I get this output

Enter speed and acceleration: 60 3.5

The minimum runway length for this airplane is 6300.0

*Learning language is easy but learning basics is difficult*

posted 8 months ago

Double check whether the division is happening before or after the multiplication. Are assignment operators evaluated left to right, or right to left?

As a side note: It seems rather overkill to import the Math library here when a simple

As a side note: It seems rather overkill to import the Math library here when a simple

`(speed * speed)`would suffice.Tim Driven Development

posted 8 months ago

Thanks ！ I have figured it out

Tim Cooke wrote:Double check whether the division is happening before or after the multiplication. Are assignment operators evaluated left to right, or right to left?

As a side note: It seems rather overkill to import the Math library here when a simple(speed * speed)would suffice.

Thanks ！ I have figured it out

*Learning language is easy but learning basics is difficult*

posted 8 months ago

"v" is a TERRIBLE name for a variable. what does it represent? what does it mean?

if the formula is v^2/2a, why aren't you coding it do to that? you can use parentesis to force a different order of operations that what Java wants to default to...

if the formula is v^2/2a, why aren't you coding it do to that? you can use parentesis to force a different order of operations that what Java wants to default to...

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors

Campbell Ritchie

Marshal

Posts: 56536

172

posted 8 months ago

You do need brackets. But not where you think. Forget that you are trying to calculate x². x² ÷ 2

or

Don't use

*a*should read x² ÷ (2*a*) which you can rewrite as x² ÷ (2 ×*a*) or x² ÷ 2 ÷*a*. But we still haven't finished. Avoid the square and don't use Math#pow. Write`x * x / (2 * a)`or

`x * x / 2 / a`Don't use

`float`s. Use`double`s instead.With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |