Square root by hand: Difference between revisions

m (Thundergnat moved page Square Root by Hand to Square root by hand: Follow normal task title capitalization policy)
Line 178:
0.01
</pre>
 
=={{header|Java}}==
{{trans|D}}
<lang java>import java.math.BigInteger;
 
public class SquareRoot {
public static final BigInteger ONE_HUNDRED = BigInteger.valueOf(100);
public static final BigInteger TWENTY = BigInteger.valueOf(20);
 
public static void main(String[] args) {
var i = BigInteger.TWO;
var j = BigInteger.valueOf((long) Math.floor(Math.sqrt(2.0)));
var k = j;
var d = j;
int n = 500;
int n0 = n;
do {
System.out.print(d);
i = i.subtract(k.multiply(d)).multiply(ONE_HUNDRED);
k = TWENTY.multiply(j);
for (d = BigInteger.ONE; d.compareTo(BigInteger.TEN) <= 0; d = d.add(BigInteger.ONE)) {
if (k.add(d).multiply(d).compareTo(i) > 0) {
d = d.subtract(BigInteger.ONE);
break;
}
}
j = j.multiply(BigInteger.TEN).add(d);
k = k.add(d);
if (n0 > 0) {
n--;
}
} while (n > 0);
System.out.println();
}
}</lang>
{{out}}
<pre>14142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727350138462309122970249248360558507372126441214970999358314132226659275055927557999505011527820605714701095599716059702745345968620147285174186408891986095523292304843087143214508397626036279952514079896872533965463318088296406206152583523950547457502877599617298355752203375318570113543746034084988471603868999706990048150305440277903164542478230684929369186215805784631115966687130130156185689872372</pre>
 
=={{header|Julia}}==
1,452

edits