牛客:球的半径和体积

在这里插入图片描述

public class BollRadius {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x0 = sc.nextInt();
        int y0 = sc.nextInt();
        int z0 = sc.nextInt();
        int x1 = sc.nextInt();
        int y1 = sc.nextInt();
        int z1 = sc.nextInt();
        
        //sqrt:根号 Math.pow(底数,几次方)
        double R = Math.sqrt(Math.pow( x0- x1,2) + Math.pow(y0 - y1,2) + Math.pow(z0- z1,2));
        double V = (4/3.0) *Math.acos(-1) * Math.pow(R,3);
        //球的体积:(4/3)* PI *r^3   Math.acos() 返回一个数的反余弦值
        //Math.acos(-1)的值为3.141592653589793

        //System.out.println(new DecimalFormat("0.000").format(R));
        //取R的一位整数三位小数,小数点前只有一个0,小数点后有 3个0
        //1 和 2 表达的意思是一样的
        DecimalFormat format = new DecimalFormat("0.000");
        System.out.println(format.format(R) + " " + format.format(V));
        //2
        //System.out.println(new DecimalFormat("0.000").format(R) + " " + new DecimalFormat("0.000").format(V));

    }
}

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值