How to write a java program to calculate the curved surface area of a cube? Here we cover the code in three different ways. Using standard values, command line arguments, method calling. Do check out, at the end of the codes; we also added an online execution tool such that you can execute each program individually. For more programs do check out here: Beginner Programs with outputs and Java interview programs for beginners here.
[wp_ad_camp_1]
Table of contents:
[table id=2 /]
Q: How to calculate the curved surface area of the cube?
A: Here, the Curved surface area is total area of the curved path. The math formula is:
Java Code Example – 1 ( Using Standard Values with Outputs )
[wp_ad_camp_3]
Here we used standard values, ( 4 x a x a). You can use the below sample in all math oriented programs. Followed by command line arguments ( parse Java) and method calling method. At the end of the three programs, we do also embed an online execution tool, where you can execute the below codes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import java.util.Scanner; class CurvedSurfaceAreaOfCube { public static void main(String args[]) { Scanner s= new Scanner(System.in); System.out.println("Enter the side of cube:"); double side=s.nextDouble(); double v=4*side*side; System.out.println("CurvedSurfaceArea Of Cube is:" +v); } } |
Output ( For standard Values – 1 )
1 2 |
Enter the side of cube:4 CurvedSurfaceArea Of Cube is:64.0 |
Code: 2 ( Using Command-Line Arguments )
[wp_ad_camp_3]
Here we used command line arguments, here we share a complete guide on what are command line arguments in java with examples. Do check it out. In simple command line arguments are, displaying inputs through the console. Here is the sample program for the curved surface area of the cube.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import java.util.Scanner; class CurvedSurfaceAreaOfCube1 { public static void main(String args[]) { double side=Double.parseDouble(args[0]); double v=4*side*side; System.out.println("CurvedSurfaceArea Of Cube is:" +v); } } |
Output: ( Using command line arguments )
1 2 3 |
javac CurvedSurfaceAreaOfCube1.java java CurvedSurfaceAreaOfCube1 4 CurvedSurfaceArea Of Cube is:64.0 |
Sample Program -3 ( Using method calling )
Here we used method calling, do check it out
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import java.util.Scanner; class CurvedSurfaceAreaOfCube { public static void main(String args[]) { Scanner s= new Scanner(System.in); System.out.println("Enter the side of cube:"); double side=s.nextDouble(); double a=CurvedSurfaceAreaOfCube.area(side); System.out.println("CurvedSurfaceArea Of Cube is:" +a ); } public static double area(double side) { double a=4*side*side; return a; } } |
Output: ( Using Return Invoke Method )
1 2 |
Enter the side of cube:4 CurvedSurfaceArea Of Cube is:64.0 |
Soon, we are going to add an online execution tool, where you can execute each program. In case if you need any custom program for your project do contact us.