Results 1 to 16 of 16
  1. #1
    atiyarose17 is offline Member
    Join Date
    Oct 2012
    Posts
    12
    Rep Power
    0

    Default 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. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default 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. #3
    atiyarose17 is offline Member
    Join Date
    Oct 2012
    Posts
    12
    Rep Power
    0

    Default 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. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,331
    Rep Power
    25

    Default Re: Math.sqrt not working!

    What version of java are you using? Is it before autoboxing?
    Last edited by Norm; 10-10-2012 at 12:23 AM.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    atiyarose17 is offline Member
    Join Date
    Oct 2012
    Posts
    12
    Rep Power
    0

    Default 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 12:20 AM.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,331
    Rep Power
    25

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

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Math.sqrt not working!

    Quote Originally Posted by atiyarose17 View Post
    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.
    No, I'm not talking about this program. I am asking if you've got another class somewhere on the class path called Math.java?

  8. #8
    atiyarose17 is offline Member
    Join Date
    Oct 2012
    Posts
    12
    Rep Power
    0

    Default Re: Math.sqrt not working!

    Quote Originally Posted by Norm View Post
    Use the -version option: javac -version

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

  9. #9
    atiyarose17 is offline Member
    Join Date
    Oct 2012
    Posts
    12
    Rep Power
    0

    Default Re: Math.sqrt not working!

    Quote Originally Posted by Fubarable View Post
    No, I'm not talking about this program. I am asking if you've got another class somewhere on the class path called Math.java?
    I don't know what a class path is. What am I looking for?

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  11. #11
    atiyarose17 is offline Member
    Join Date
    Oct 2012
    Posts
    12
    Rep Power
    0

    Default Re: Math.sqrt not working!

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

  12. #12
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

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

  13. #13
    atiyarose17 is offline Member
    Join Date
    Oct 2012
    Posts
    12
    Rep Power
    0

    Default Re: Math.sqrt not working!

    Quote Originally Posted by Fubarable View Post
    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!

  14. #14
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

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

  15. #15
    atiyarose17 is offline Member
    Join Date
    Oct 2012
    Posts
    12
    Rep Power
    0

    Default Re: Math.sqrt not working!

    Quote Originally Posted by Fubarable View Post
    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?

  16. #16
    atiyarose17 is offline Member
    Join Date
    Oct 2012
    Posts
    12
    Rep Power
    0

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

Similar Threads

  1. Math.sqrt is not working
    By GoingDarkness in forum NetBeans
    Replies: 5
    Last Post: 04-08-2012, 05:31 AM
  2. Adding a sqrt button and percentage button to a calculator
    By Josie_Taylor in forum New To Java
    Replies: 4
    Last Post: 03-14-2011, 01:16 AM
  3. Replies: 3
    Last Post: 03-08-2011, 05:15 AM
  4. Create Math.sin without math.sin
    By vudoo in forum New To Java
    Replies: 11
    Last Post: 12-07-2010, 06:23 AM
  5. Replies: 8
    Last Post: 05-28-2008, 07:00 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •