201k views
1 vote
The surface area of a cube can be known if we know the length of an edge. Write a java program that takes the length of an edge (an integer) as input and prints the cube’s surface area as output.

1 Answer

4 votes

Answer:

import java.util.Scanner;

public class CubeSurfaceArea {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in); // create a Scanner object to read input from the user

System.out.print("Enter the length of the edge: ");

int length = sc.nextInt(); // read an integer input from the user and store it in the variable length

int surfaceArea = 6 * length * length; // calculate the surface area of the cube using the formula 6 * length * length

System.out.println("The surface area of the cube is " + surfaceArea + "."); // print the surface area to the console

}

}

User Pratik Kumar
by
8.5k points

No related questions found