# Square root

• (2 Pages)
• 1
• 2

## 20 Replies - 190619 Views - Last Post: 08 August 2010 - 08:03 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=12682&amp;s=7a34780c6a43bcaea9b3a88645f4d559&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Drift-O-Manaic

Reputation: 0
• Posts: 83
• Joined: 19-August 05

# Square root

Posted 11 October 2005 - 09:30 AM

In one of my programs i need to be able to find the square root of a number bu i cant find any easy way to do this.

Is there any easy way to find the square root?
Is This A Good Question/Topic? 0

### #10 Nova Dragoon

• The Innocent Shall Suffer, Big Time

Reputation: 36
• Posts: 6,169
• Joined: 16-August 01

## Re: Square root

Posted 11 October 2005 - 09:32 AM

Math.sqrt(i)

from java.lang.Math

### #11 Drift-O-Manaic

Reputation: 0
• Posts: 83
• Joined: 19-August 05

## Re: Square root

Posted 11 October 2005 - 09:40 AM

Thanks!!! Works like a charm.

is there an easy way to square a number?

I have just been doing it like this (a*a).

### #12 Nova Dragoon

• The Innocent Shall Suffer, Big Time

Reputation: 36
• Posts: 6,169
• Joined: 16-August 01

## Re: Square root

Posted 11 October 2005 - 09:40 AM

There is also a pow() function

a little bit of google goes along way:
http://stein.cshl.or....lang.Math.html

### #13 cheezit

Reputation: 1
• Posts: 5
• Joined: 09-October 05

## Re: Square root

Posted 12 October 2005 - 04:48 PM

isn't it Math.pow(i,2)
and the 2 means what power the i is raised to?

• g+ + -o drink whiskey.cpp

Reputation: 250
• Posts: 13,507
• Joined: 12-July 02

## Re: Square root

Posted 12 October 2005 - 05:51 PM

The qualifying path to the proper class library depends on what libraries you have imported...Math is the class library...pow() is the function within that library. And yes, in the example of pow(a,B), a is raised to the power of b.

### #15 born2c0de

• printf("I'm a %XR",195936478);

Reputation: 187
• Posts: 4,673
• Joined: 26-November 04

## Re: Square root

Posted 13 October 2005 - 12:56 AM

There's also an approximation method.
See this snippet here.

It's not Java Code but it will be with little modifications....but i figure you will at least get the algorithm right.

### #16 Kevin137

Reputation: 0
• Posts: 16
• Joined: 23-January 08

## Re: Square root

Posted 01 April 2009 - 12:26 PM

Does anyone know how to have to square root symbol actually show up as output?

### #17 Kevin137

Reputation: 0
• Posts: 16
• Joined: 23-January 08

## Re: Square root

Posted 01 April 2009 - 12:46 PM

On a PC that is, not a a Mac

### #18 pbl

• There is nothing you can't do with a JTable

Reputation: 8378
• Posts: 31,956
• Joined: 06-March 08

## Re: Square root

Posted 01 April 2009 - 08:13 PM

Drift-O-Manaic, on 11 Oct, 2005 - 08:40 AM, said:

Thanks!!! Works like a charm.

is there an easy way to square a number?

I have just been doing it like this (a*a).

But if you really want to sqare... this is the easy one
Use pow() if the exposant is a floating number

### #19 Locke

• Sarcasm Extraordinaire!

Reputation: 550
• Posts: 5,624
• Joined: 20-March 08

## Re: Square root

Posted 01 April 2009 - 10:11 PM

And, no, I don't think we can have a good square root symbol show up on the output.

### #20 priya_lorha

Reputation: 6
• Posts: 82
• Joined: 02-August 08

## Re: Square root

Posted 02 April 2009 - 01:24 AM

Yes, Maths.sqrt(number)

Reputation:

## Re: Square root

Posted 14 July 2010 - 04:29 AM

cheezit, on 12 October 2005 - 03:48 PM, said:

isn't it Math.pow(i,2)
and the 2 means what power the i is raised to?

### #22 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 12278
• Posts: 45,364
• Joined: 27-December 08

## Re: Square root

Posted 14 July 2010 - 05:37 AM

### #23 Luckless

• </luck>

Reputation: 293
• Posts: 1,146
• Joined: 31-August 09

## Re: Square root

Posted 14 July 2010 - 06:03 AM

extended ASCII code 251 (at least the sheet says it is) is a square root symbol. Why not just display that?
```int i = 4;
char square = 251;
double j = math.pow(i,1/2);
System.out.println(square + "" i + " is " + j);

```

I am getting the wrong ASCII code though. Does Java have problems with extended ASCII?