JAVA面试要点011---java中一个数的n次方怎么写

版权声明:本文为博主原创文章,未经博主credreamer 允许不得转载 违者追究法律责任。 https://blog.csdn.net/lidew521/article/details/83754845

    JAVA技术交流QQ群:170933152  

第一步我们首先查看一下Math数学函数的API,可以看到pow()方法返回第一个参数的第二个参数次方,格式为Math.pow(m,n),代表m的n次方,如下图所示: 

//获取4位短信验证码
public static String getVerCode(Integer len) {
    Random random = new Random();
    double c=Math.pow(10,len);
    String fourRandom = random.nextInt(new Double(c).intValue()) + "";
    int randLength = fourRandom.length();
    if (randLength < len) {
        for (int i = 1; i <= len - randLength; i++)
            fourRandom = "0" + fourRandom;
    }
    return fourRandom;
}

猜你喜欢

转载自blog.csdn.net/lidew521/article/details/83754845