GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes How do I square root a Double? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How do I square root a Double?" Watch "How do I square root a Double?" New topic
Author

How do I square root a Double?

Conrad McLaughlin
Greenhorn

Joined: Jan 31, 2006
Posts: 27
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

Joined: Jul 08, 2003
Posts: 24187
    
  34

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.


[Jess in Action][AskingGoodQuestions]
 
GeeCON Prague 2014
 
subject: How do I square root a Double?