Skip to content

Instantly share code, notes, and snippets.

@joeyv
Created October 21, 2013 17:34
Show Gist options
  • Save joeyv/7087765 to your computer and use it in GitHub Desktop.
Save joeyv/7087765 to your computer and use it in GitHub Desktop.
Cubes two inputs and adds them
import java.util.Scanner;
public class Cubes
{
public static void main(String[] args)
{
// Declare variables
double cube1, cube2;
double sum;
Scanner sc = new Scanner(System.in);
// Get input
cube1 = sc.nextInt();
cube2 = sc.nextInt();
// Calculate cubes and sum
cube1 = (Math.pow(cube1, 3));
cube2 = (Math.pow(cube2, 3));
sum = cube1 + cube2;
// Output result
System.out.println("Cube 1: " + cube1 + "\nCube 2: " + cube2 + "\nSum is: " + sum);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment