Jump to content

Class for calculating the root of something

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
GMVResources

GMVResources

    Learning Programmer

  • Members
  • PipPipPip
  • 72 posts
class NewRoot {

    public static void main(String[] args) {

        int number = 100; // this is where you put what number you want

        // for the program to calculate

        if (args.length > 0) {

            number = Integer.parseInt(args[0]);

    }

        System.out.println("The square root of "

                + number // this part neatly puts the square root into a sentence

                // for you =D

                + " is "

                + Math.sqrt(number) );

    }

}

Edited by Orjan, 08 August 2010 - 04:59 AM.


#2
Guest

Guest

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 3,414 posts
This is barely a snippet, not even close to a tutorial. It's not even in code tags :/
Root Beer == System Administrator's Beer
Download the new operating system programming kit! (some assembly required)

#3
Roman Y

Roman Y

    Programmer

  • Members
  • PipPipPipPip
  • 189 posts
this one with the squere root got me thinking of complex numbers and java... Does anybody know if Java has any class or library that can calculate complex numbers as well operations between complex numbers as generating a complex number when you're trying to take a sqrt of a negative number. Or do you have to make that class on your own?

#4
d0s

d0s

    Newbie

  • Members
  • PipPip
  • 10 posts

Guest said:

This is barely a snippet, not even close to a tutorial. It's not even in code tags :/

Not to mention kind of a complete mistunderstanding of how to properly use objects :/

Square rooting a number is a method performed on an object (the number), not an object in and of itself. Its like getting your nouns and verbs mixed up. I could see taking say a floating point variable object and extending it to include a square root function... but square root as its own object? Lolz.

#5
Guest

Guest

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 3,414 posts

Roman Y. said:

this one with the squere root got me thinking of complex numbers and java... Does anybody know if Java has any class or library that can calculate complex numbers as well operations between complex numbers as generating a complex number when you're trying to take a sqrt of a negative number. Or do you have to make that class on your own?
I searched Google and apparently Java does not have a complex number class included in the standard library. It surprises me, because C includes one, and it's a dead simple language.
Of course you don't have to program a class of your own, as others have already some:
Complex.java
Complex numbers (Java) - LiteratePrograms

Edit: Oh, and I agree with d0s.
Root Beer == System Administrator's Beer
Download the new operating system programming kit! (some assembly required)