Results 1 to 16 of 16
Thread: Math.sqrt not working!
 10092012, 11:48 PM #1Member
 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

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.
 10102012, 12:07 AM #3Member
 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.
 10102012, 12:17 AM #4
Re: Math.sqrt not working!
What version of java are you using? Is it before autoboxing?
Last edited by Norm; 10102012 at 12:23 AM.
If you don't understand my response, don't ignore it, ask a question.
 10102012, 12:17 AM #5Member
 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_07Last edited by atiyarose17; 10102012 at 12:20 AM.
 10102012, 12:22 AM #6
Re: Math.sqrt not working!
Use the version option: javac version
If you don't understand my response, don't ignore it, ask a question.

Re: Math.sqrt not working!
 10102012, 12:25 AM #8Member
 Join Date
 Oct 2012
 Posts
 12
 Rep Power
 0
 10102012, 12:27 AM #9Member
 Join Date
 Oct 2012
 Posts
 12
 Rep Power
 0

Re: Math.sqrt not working!
Ah, boxing and unboxing  good catch Norm!
 10102012, 12:33 AM #11Member
 Join Date
 Oct 2012
 Posts
 12
 Rep Power
 0
Re: Math.sqrt not working!
What is boxing and how can I make this work? :(

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.
 10102012, 12:43 AM #13Member
 Join Date
 Oct 2012
 Posts
 12
 Rep Power
 0

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.
 10102012, 12:51 AM #15Member
 Join Date
 Oct 2012
 Posts
 12
 Rep Power
 0
 10102012, 12:55 AM #16Member
 Join Date
 Oct 2012
 Posts
 12
 Rep Power
 0
Similar Threads

Math.sqrt is not working
By GoingDarkness in forum NetBeansReplies: 5Last Post: 04082012, 05:31 AM 
Adding a sqrt button and percentage button to a calculator
By Josie_Taylor in forum New To JavaReplies: 4Last Post: 03142011, 01:16 AM 
Does any one know how to write this e^sqrt(lognloglog(n)) ,where n is biginteger
By ajay.eeralla in forum New To JavaReplies: 3Last Post: 03082011, 05:15 AM 
Create Math.sin without math.sin
By vudoo in forum New To JavaReplies: 11Last Post: 12072010, 06:23 AM 
Java mail problem(working in intranet,but not working in iternet)
By sundarjothi in forum Advanced JavaReplies: 8Last Post: 05282008, 07:00 AM
Bookmarks