Import Java.awt.desktop;import java.io.ioexception;import java.math.bigdecimal;import java.math.RoundingMode; Import Java.net.uri;import java.net.urisyntaxexception;/** * Average annual growth rate * * @author Mrchu * @version 1.0 * @date December 31, 2014 */public class Growthrateperannumutils {public static void main (string[] args) {try {uri uri = new Uri ("Http://baike.baidu . Com/link?url=hp48p6gifuy49ajln3oojnzjlu1jig9nm6izbmbbz06yjgtnbn7dqgmesklszc0jua6rke1tu0ycki2j-bcem_ ");D Esktop.getdesktop (). browse (URI); catch (URISyntaxException e) {e.printstacktrace ();} catch (IOException e) {e.printstacktrace ();} Double x = 1762.5/991.04;double n = 1.0/3.0; System.out.println (getgrowthrateperannumwithpercent (x, n)); /** * Get average annual growth rate * @param x * @param n * @return * Average annual growth */public static double Getgrowthrateperannum (double x, double n) {re Turn Math.pow (x, N)-1;} /** * Average annual growth rate * @param x * @param n * @return * Average annual growth rate, retain two digits after the decimal point */public static BigDecimal Getgrowthrateperannumwithroundin g (double x, double n) {BigDecimal BD = New BigDecimal ((Math.pow (x, N)-1); return Bd.setscale (2, roundingmode.half_up);} /** * Get average annual growth rate * @param x * @param n * @return * Average annual growth rate, two digits after the decimal point, and a percent sign for */public static String GETGROWTHRATEPERANNUMWITHPE Rcent (double x, double n) {BigDecimal BD = new BigDecimal ((Math.pow (x, N)-1); return Bd.setscale (2, RoundingMode.H ALF_UP) + "%";}}
Java calculates average annual growth rate