# Math.sqrt not working!

• 10-09-2012, 11:48 PM
atiyarose17
Math.sqrt not working!
HELP!!! Math.sqrt isn't working for me for some reason! I am working with calculating numbers and this is my code:

Code:

```import java.util.*; public class Assignment1 {   public static void main(String[] args) {         //declare variables     Scanner scan;     Double number, guess,y,x,root,diff;         //ask the user for a number, and print it out     scan = new Scanner(System.in);     System.out.println("Enter any number:");         //check to make sure they entered a valid number      while(!scan.hasNextDouble()) {       scan = new Scanner(System.in);       System.out.println("Enter any number:");     }         //store the number as a double and print out the number     number = scan.nextDouble();     System.out.println("You entered the number " +number);              //ask user for their best guess at the square root, and print out the guess     scan = new Scanner(System.in);     System.out.println("Enter your best guess of the square root of that number:");         //check to make sure they entered a valid number      while(!scan.hasNextDouble()) {       scan = new Scanner(System.in);       System.out.println("Enter your best guess of the square root of that number:");     }         //store the guess as a double and print out the guess     guess = scan.nextDouble();     System.out.println("Your best guess of the square root is " + guess);         //create columns for steps and results     System.out.println("Step\tResult");         //x0 is y and y is therefore equal to the guess     y = guess;         //loop for six steps using the result from the previous step as the "guess" for the next step     int counter = 1;     for(counter= 1; counter <= 6; counter++){       x = ((y+(number/y))/2);       System.out.println(counter + "\t" + x);       y=x;     }         //find the actual value of the square root     root = Math.sqrt(number); } }```

and this is the error I'm getting:

1 error found:
File: C:\Users\atieh\Compsci\Assignment1.java [line: 54]
Error: cannot find symbol
symbol: method sqrt(java.lang.Double)
location: class Math
• 10-09-2012, 11:58 PM
Fubarable
Re: Math.sqrt not working!
Look through the classes you've created, find the one that you've named Math, and change its name to something else.
• 10-10-2012, 12:07 AM
atiyarose17
Re: Math.sqrt not working!
throughout the code there is nothing named Math. Using Find on Dr Java, the "Math.sqrt" is the only word "math" in the code, as well as the file is saved as Assignment1 and doesn't have the word Math in it.
• 10-10-2012, 12:17 AM
Norm
Re: Math.sqrt not working!
What version of java are you using? Is it before autoboxing?
• 10-10-2012, 12:17 AM
atiyarose17
Re: Math.sqrt not working!
how do I find out what version of java I'm using?

edit: in my program files, my java is jdk1.7.0_07
• 10-10-2012, 12:22 AM
Norm
Re: Math.sqrt not working!
Use the -version option: javac -version
• 10-10-2012, 12:22 AM
Fubarable
Re: Math.sqrt not working!
Quote:

Originally Posted by atiyarose17
throughout the code there is nothing named Math. Using Find on Dr Java, the "Math.sqrt" is the only word "math" in the code, as well as the file is saved as Assignment1 and doesn't have the word Math in it.

• 10-10-2012, 12:25 AM
atiyarose17
Re: Math.sqrt not working!
Quote:

Originally Posted by Norm
Use the -version option: javac -version

I'm sorry I have no idea what this means :(
• 10-10-2012, 12:27 AM
atiyarose17
Re: Math.sqrt not working!
Quote:

Originally Posted by Fubarable

I don't know what a class path is. What am I looking for?
• 10-10-2012, 12:29 AM
Fubarable
Re: Math.sqrt not working!
Ah, boxing and unboxing -- good catch Norm!
• 10-10-2012, 12:33 AM
atiyarose17
Re: Math.sqrt not working!
What is boxing and how can I make this work? :(
• 10-10-2012, 12:40 AM
Fubarable
Re: Math.sqrt not working!
First go to your command line and and do what Norm recommends -- find out what version of Java you're compiling with.
• 10-10-2012, 12:43 AM
atiyarose17
Re: Math.sqrt not working!
Quote:

Originally Posted by Fubarable
First go to your command line and and do what Norm recommends -- find out what version of Java you're compiling with.

Oh dear. I guess this "new to java" doesn't mean new to first year university computer science. I have no idea what any of you are talking about. I'm sorry for wasting your time. Thank you for your input and for trying to help me!
• 10-10-2012, 12:47 AM
Fubarable
Re: Math.sqrt not working!
Are you running on a windows computer? If so, click the start button and type in cmd.exe. Then enter what Norm suggests in the cmd window that pops up. Don't give up.
• 10-10-2012, 12:51 AM
atiyarose17
Re: Math.sqrt not working!
Quote:

Originally Posted by Fubarable
Are you running on a windows computer? If so, click the start button and type in cmd.exe. Then enter what Norm suggests in the cmd window that pops up. Don't give up.

what exactly do I enter in the cmd window?
• 10-10-2012, 12:55 AM
atiyarose17
Re: Math.sqrt not working!
I think I might've just fixed my problem by accident. I moved a few things around and BAM .. she compiled like a breeze... No idea how that happened but I'll take it. Thanks for your help!!