Computer Science, asked by heroharvinder, 4 days ago

WAP to calculate TSA,LSA, volume,Diagonal of cube using scanner class​

Answers

Answered by mp6053219
0

Explanation:

Java Program to find Volume and Surface Area of Cube

Write Java Program to find Volume and Surface Area of Cube with example. Before we step into the Java Program to find Volume and Surface Area of Cube, Let see the definitions and formulas behind the Surface area of a Cube and Volume of a Cube

Java Cube Program

All the edges in the Cube have the same length. We can say, Cube is nothing but six equal squares.

Surface Area of a Cube

If we know the length of an edge in a Cube, then we can calculate the surface area of a Cube using the formula:

Surface Area of a Cube = 6l² (Where l is the Length of any side of a Cube).

Area of a square = l² Since the Cube made of 6 equal squares, Surface Area of a Cube = 6l²

If we already know the Surface Area of Cube and then we can calculate the length of any side by altering the above formula as:

l = √sa / 6 (sa = Surface Area of a Cube)

The volume of a Java Cube

The amount space inside the Cube is called Volume. If we know the length of any edge of a Cube, then we can calculate the Volume of Cube using the formula.

Answered by Anonymous
2

TSA, LSA, Volume, Diagonal of Cube - Java

We are asked to write a Java program to calculate TSA, LSA, Volume, Diagonal of Cube using Scanner class.

We need first to take user input to accept the length of any side of a Cube. We will do this by using the Scanner class.

We store the length of the side as a double data type value. Then, we calculate TSA, LSA, Volume, Diagonal of Cube using respective formulae and display it.

TSA of Cube

The Total surface area of a Cube is equal to the product of 6 and two times the length of any side of a cube.

\boxed{TSA = 6a^2}

LSA of Cube

The Total surface area of a Cube is equal to the product of 4 and two times the length of any side of a cube.

\boxed{LSA = 4a^2}

Volume of Cube

The Volume of a Cube is equal to three times the length of any side of a cube.

\boxed{Volume = a*a*a = a^3}

Diagonal of Cube

The Diagonal of a Cube is equal to the product of 3 and the square root of the length of any side of a cube.

\boxed{Diagonal = 3\sqrt{a}}

* Note

The surface areas are measured in terms of square units, whereas the volume of the cube is measured in terms of cubic units.

The Java Program

Here's the Java program to calculate the TSA, LSA, Volume, Diagonal of Cube using Scanner class:

import java.util.Scanner;   // Importing Scanner Class

public class Cube { // Creating Class

   // The MAIN function

   public static void main(String[] args) {

       // Storing Lateral surface area (LSA), Total surface area (TSA), Volume and Diagonal of the Cube as double data type value

       double LSA, TSA, Volume, Diagonal, a;

       // Creating object of scanner

       Scanner sc = new Scanner(System.in);

       // Taking user input to accept the length of any side of the Cube

       System.out.print("Enter the length of any side of the cube: ");

       a = sc.nextDouble();

       // Calculating Total surface area (TSA) of Cube

       TSA = 6*(Math.pow(a,2));

       // Calculating Lateral surface area (LSA) of Cube

       LSA = 4*(Math.pow(a,2));

       // Calculating Volume of Cube

       Volume = Math.pow(a,3);

       // Calculating Digonal of Cube

       Diagonal = 3*(Math.sqrt(a));

       // Displaying the answer of Total surface area (TSA) of Cube

       System.out.format("\n The Total surface area of a Cube = %.2f square units", TSA);

       // Displaying the answer of Lateral surface area (LSA) of Cube

       System.out.format("\n The Lateral surface area of a Cube = %.2f square units", LSA);

       // Displaying the answer of Volume of Cube

       System.out.format("\n The Volume a Cube = %.2f cubic units", Volume);

       // Displaying the answer of Diagonal of Cube

       System.out.format("\n The Diagonal of a Cube = %.2f units", Diagonal);

   }

}

\rule{300}{2}

Screenshots of the Java Program co‎de and Sample output have been attached.

Attachments:
Similar questions