出力を小数点以下 4 桁に四捨五入する必要がありますが、自分の処理が希望どおりに実行される方法がよくわかりません。最後の小数点以下 4 桁を四捨五入する必要があります
import java.util.Scanner; //Needed for the Scanner class
public class SphereCalculations
{
public static void main(String[] args) //all the action happens here!
{ Scanner input = new Scanner (System.in);
double radius;
double volume;
double surfaceArea;
System.out.println("Welcome to the Sphere Calculator. ");
System.out.print( "Enter radius of sphere: " );
radius = input.nextDouble();
volume = ((4.0 / 3.0) * (Math.PI * Math.pow(radius, 3)));
surfaceArea = 4 * (Math.PI * Math.pow(radius, 2));
System.out.println("The Results are: ");
System.out.println("Radius: " + radius);
System.out.println("Sphere volume is: " + volume);
System.out.println("Sphere Surface Area is: " + surfaceArea);
}
}
出力:
Radius: 7.5
Volume: 1767.1459
Surface Area: 706.8583