【发布时间】:2020-10-31 19:24:56
【问题描述】:
import java.util.Scanner;
import javax.swing.plaf.basic.BasicInternalFrameTitlePane.SystemMenuBar;
class Main {
public static void main(String[] args) {
System.out.println("My name is Akhil Madusudan");
System.out.println("This program calculates the volume and surface area of a cuboid");
Scanner l = new Scanner(System.in);
System.out.println("Enter the cuboid length:");
double length = l.nextDouble();
Scanner h = new Scanner(System.in);
System.out.println("Enter the cuboid height:");
double height = h.nextDouble();
Scanner w = new Scanner(System.in);
System.out.println("Enter the cuboid width:");
double width = w.nextDouble();
double cuboidVolume;
cuboidVolume = (length * width * height);
double surfaceArea;
surfaceArea = ((2) * width * length + (2) * length * height + (2) * width * height);
System.out.printf("Volume of the cuboid (Length: " + length + "/Height: " + height + "/ Width: " + width + ") is " + cuboidVolume);
}
}
【问题讨论】:
-
将值转换为字符串并检查小数点后的长度,如果等于2则打印
-
参考你可以使用这个stackoverflow.com/a/6264613/9050514