1. Member
Join Date
Oct 2012
Posts
12
Rep Power
0

## 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:

Java 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

2. ## 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.

3. Member
Join Date
Oct 2012
Posts
12
Rep Power
0

## 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.

4. ## Re: Math.sqrt not working!

What version of java are you using? Is it before autoboxing?
Last edited by Norm; 10-10-2012 at 01:23 AM.

5. Member
Join Date
Oct 2012
Posts
12
Rep Power
0

## 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
Last edited by atiyarose17; 10-10-2012 at 01:20 AM.

6. ## Re: Math.sqrt not working!

Use the -version option: javac -version

7. ## Re: Math.sqrt not working!

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.

8. Member
Join Date
Oct 2012
Posts
12
Rep Power
0

## Re: Math.sqrt not working!

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

I'm sorry I have no idea what this means :(

9. Member
Join Date
Oct 2012
Posts
12
Rep Power
0

## Re: Math.sqrt not working!

Originally Posted by Fubarable
I don't know what a class path is. What am I looking for?

10. Member
Join Date
Oct 2012
Posts
12
Rep Power
0

## Re: Math.sqrt not working!

What is boxing and how can I make this work? :(

11. ## 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.

12. Member
Join Date
Oct 2012
Posts
12
Rep Power
0

## Re: Math.sqrt not working!

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!

13. ## 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.

14. Member
Join Date
Oct 2012
Posts
12
Rep Power
0

## Re: Math.sqrt not working!

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?

15. Member
Join Date
Oct 2012
Posts
12
Rep Power
0

## 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!!