gpt4 book ai didi

java - Float/Double 似乎不起作用。结果一直是整数

转载 作者:行者123 更新时间:2023-12-02 16:34:47 24 4
gpt4 key购买 nike

<分区>

import java.util.Scanner;

public class Test {

public static void main(String[] args) {

Scanner userInput = new Scanner(System.in);

final double PI = Math.PI;
final double sphereVolumeConstant = (4/3);

System.out.println("Volume of a sphere.");

System.out.print("Radius of sphere: ");
double radius = userInput.nextDouble();

double volumeOfSphere = sphereVolumeConstant * PI * Math.pow(radius, 3);

System.out.println("Volume = " + sphereVolumeConstant);
}

}

终端:

Volume of a sphere.
Radius of sphere: 5
Volume = 1.0

我正在尝试计算常量本身,它一直是一个整数,即使它不应该,或者至少我认为它不应该。有人可以帮忙/解释一下吗?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com