@GeorgeGibby/

AP Comp Sci 1.05 - Cube

Java

No description

fork
loading
Files
  • Main.java
Main.java
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
33
34
35
36
37
38
39
40
41
42
/*
* Finds the surface area of a cube.
*
* George Gibby
*
* September 18, 2018
*
* Input: Length of one side.
* Outputs: The surface area of the cube,
*          Volume,
*          And the distance of its diagonal.
*/
import java.util.Scanner;

public class Main
{
  public static void main(String[] args)
  {
    //Initialize the variable
    double sideLength;
    double surfaceArea;
    double volume;
    double diagonal;

    //Initialize the Scanner
    Scanner reader = new Scanner(System.in);

    //Take the input data
    System.out.print("Cube side length: ");
    sideLength = reader.nextDouble();

    //Math time
    volume = Math.pow(sideLength, 3);
    diagonal = sideLength * Math.sqrt(2);
    surfaceArea = (sideLength*sideLength) * 6;

    //print results
    System.out.println("Surface Area: " + surfaceArea);
    System.out.println("Diagonal: " + diagonal);
    System.out.println("Volume: " + volume);
  }
}