Results 1 to 6 of 6
  1. #1
    GoingDarkness is offline Member
    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0

    Exclamation Math.sqrt is not working

    Hi, I am a bit new to java and a simple command I want to use does not work in NetBeans. Every time I type Math.sqrt(number) sqrt can never be found.
    Java Code:
    class Root{
        public static void main(String[] args){
            int number = 225;
            System.out.println("The square root of "
                    + number
                    + " is "
                    + Math.sqrt(number)
                    );
        }
    }
    That is my code, can someone help me if I am doing anything wrong?
    Last edited by pbrockway2; 04-08-2012 at 05:08 AM. Reason: code tags added

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: Math.sqrt is not working

    That code works fine for me. Make sure you haven't defined your own class called Math which is getting the road of the compiler locating the java.lang.Math class.

    -----

    Also, when you post code use the "code" tags. Put [code] at the start of the code and [/code] at the end to ensure that the code is readable when it appears here.
    Last edited by pbrockway2; 04-08-2012 at 05:09 AM.

  3. #3
    GoingDarkness is offline Member
    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0

    Default Re: Math.sqrt is not working

    Quote Originally Posted by pbrockway2 View Post
    That code works fine for me. Make sure you haven't defined your own class called Math which is getting the road of the compiler locating the java.lang.Math class.

    -----

    Also, when you post code use the "code" tags. Put [code] at the start of the code and [/code] at the end to ensure that the code is readable when it appears here.
    Math.sqrt is not working-math.png Is this stopping me?

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

  5. #5
    GoingDarkness is offline Member
    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0

    Default Re: Math.sqrt is not working

    Thank you so much!!! :)

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

Similar Threads

  1. 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, 02:16 AM
  2. Replies: 3
    Last Post: 03-08-2011, 06:15 AM
  3. Replies: 2
    Last Post: 01-04-2011, 05:30 AM
  4. Create Math.sin without math.sin
    By vudoo in forum New To Java
    Replies: 11
    Last Post: 12-07-2010, 07:23 AM
  5. Replies: 8
    Last Post: 05-28-2008, 08: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
  •