1
String LOA, LWL, Beam, Displacement, SailArea;
LOA = stdin.readLine(); //(LOA) Total Length of Vessel
System.out.println("LOA: " + (LOA));
System.out.println("HullSpeed: " + (1.34 * Math.pow(LWL, 0.5)));

Can I get help? I'm new to java and have no idea how to fix this error with the last LWL.
incompatible types: String cannot be converted to double

2
  • What is the value of LWL? Commented Sep 9, 2015 at 6:24
  • is there a way to use while or for loops? Commented Sep 9, 2015 at 6:41

2 Answers 2

5

If LWL is a String that represents a Double, try parsing that Double by using Double.parseDouble:

Double LWLDouble = Double.parseDouble(LWL);
System.out.println("HullSpeed: " + (1.34 * Math.pow(LWLDouble, 0.5)));

It's reasonable that you can not use a mathematical operations on a String.

Sign up to request clarification or add additional context in comments.

Comments

0

See this part of your code,

System.out.println("HullSpeed: " + (1.34 * Math.pow(LWL, 0.5)));

Here, LWL is of String type Math.pow() does not take a String argument it takes a double.

More on types in Java here and here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.