第五届蓝桥杯JavaA组第三题

如果x的x次幂结果为10(参见【图1.png】),你能计算出x的近似值吗?

显然,这个值是介于2和3之间的一个数字。

请把x的值计算到小数后6位(四舍五入),并填写这个小数值。

注意:只填写一个小数,不要写任何多余的符号或说明。

import java.text.DecimalFormat;

public class BB0503 {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    double x = 2.0;
    while(x<3.0){
        x = x + 0.00000001;
        if(Math.abs(Math.pow(x,x)-10.0)<0.000001){
            System.out.println(formatDouble4(x));
        }
    }
    System.out.println("1");
}

private static double pow(double x, double x2) {
    // TODO Auto-generated method stub
    return 0;
}

public static String formatDouble4(double d) {  
    DecimalFormat df = new DecimalFormat("#.000000");  
    return df.format(d);  
}  

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值