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);
}
}
Asked
Active
Viewed 26 times
0

deadshot
- 8,881
- 4
- 20
- 39
-
convert the value to string and check length after the decimal point and if it is equal 2 print it – deadshot Jul 11 '20 at 02:51
-
for reference you can use this https://stackoverflow.com/a/6264613/9050514 – deadshot Jul 11 '20 at 02:53
1 Answers
0
You only need one Scanner
. And just change
System.out.printf("Volume of the cuboid (Length: " +
length + "/Height: " + height +
"/ Width: " + width + ") is " + cuboidVolume);
to something like
System.out.printf("Volume of the cuboid (Length: "
+ "%.2f/Height: %.2f/ Width: %.2f) is %.2f%n",
length, height, width, cuboidVolume);

Elliott Frisch
- 198,278
- 20
- 158
- 249