🎯 목표 : 바빌로니아 방법으로 제곱근 구하기
public class Solution {
private static final int ACCUR = 10;
public String squareRoot(int num) {
double sqrt = PRECISION;
for (int i = 0; i < ACCUR; i++)
sqrt = 0.5 * (num / sqrt + sqrt);
// 소숫점 둘째 자리까지만 출력
return String.format("%.2f", sqrt);
}
}
References
https://ko.wikipedia.org/wiki/%EB%B0%94%EB%B9%8C%EB%A1%9C%EB%8B%88%EC%95%84_%EB%B2%95
https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method