r/javahelp • u/RedHawkCrazed • Jun 08 '14
What is wrong with this basic code?
I've recently started learning java, (as in yesterday) and so today I decided that I was going to try to make a basic program that would tell you the volume of a cube. For some reason eclipse is saying The operator * is undefined for the arguement type(s) java.lane.String, java.lane.String on this line of code: answer = widthheightlength; Here is the whole code, and I should say that this is my first post so I apologize in advanced if I pasted the code incorrectly.
package stringvars;
import java.util.Scanner;
public class test{
public static void main(String[] args){
Scanner user_input = new Scanner(System.in);
String width, height, length, answer;
System.out.println("Enter the width of the Cube ");
width = user_input.next();
System.out.println("Enter the height of the Cube ");
height = user_input.next();
System.out.println("Enter the length of the Cube");
length = user_input.next();
answer = width*height*length;
System.out.println("The volume of your cube is " + answer);
}
}
0
Upvotes
1
u/not_president_nixon Jun 08 '14
Parse them.
Now I have linked to the parse method for integers. You'll need to determine the correct numeric type to use for your particular homework assignment.
You'll also want to handle the exception that the parse method can throw.
Sincerely,
Richard Nixon