• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I square root a Double?

 
Conrad McLaughlin
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How come when I try and square root a Double I get the same answer?

eg.

Double VL = 2.0;
VL = Math.sqrt(VL);
System.out.println("VL =" + VL);


Why is the System output:
VL = 2.0
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you run that exact code in JDK 1.5.0 or later, it will print

VL =1.4142135623730951

In earlier versions of Java it won't compile.

So there's some difference between the code you're showing us and the code you actually ran -- try putting just this code into an appropriate main() and running it; then try to figure out how your actual code is different.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic