Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
/** * A utility class for calculating the perimeter of a square * using a recursive algorithm. */ public class Recursive { /** * Find the perimeter of a square that has a given area * * @param area The area of the square * @return The perimtere of the square */ public static double findPerimeterOfSquare(double area) { double perimeter, width; width = Math.sqrt(area); perimeter = increaseBy(0.0, width, 4); return perimeter; } /** * Increase a given total by a given amount a given number of times. * * @param total The value to increase * @param amount The amount of the increase * @param times The number of times to perform the increase */ private static double increaseBy(double total, double amount, int times) { if (times == 1) { return total + amount; } else { return increaseBy(total + amount, amount, times - 1); } } }