That's the whole piece of code I have. I post it again here.
sideCube is declared as this:
double sideCube = input.nextDouble();
When the user enters a double value, it is the argument for the cube_vol method but this doesn't work.
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
// calling the function
cube_vol(sideCube);
}
// Cube function
public static double cube_vol(double sideCube) {
printMe("What is the length of one of the sides: ");
Scanner input = new Scanner(System.in);
double sideCube = input.nextDouble();
double ans1 = cube_vol(sideCube);
printMe("The cube's volume is: %.2f\n", ans1);
double cubeVol = Math.pow(sideCube, 3);
return cubeVol;
}
public static void printMe (String text) {
System.out.println(text);
}
public static void printMe (String text, double value) {
System.out.printf(text, value);
}
}
--- Update ---
Got that working now
package com.langara.week4;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
cube_vol();
}
// Cube function
public static double cube_vol() {
printMe("What is the length of one of the sides: ");
Scanner input = new Scanner(System.in);
double sideCube = input.nextDouble();
double cubeVol = Math.pow(sideCube, 3);
printMe("The cube's volume is: %.2f\n", cubeVol);
return cubeVol;
}
public static void printMe (String text) {
System.out.println(text);
}
public static void printMe (String text, double value) {
System.out.printf(text, value);
}
}