Java Error

Posted on 2013-09-08
Medium Priority
Last Modified: 2013-09-08
I have a simple java program with an error on line 14 and the code looks fine. What am I missing?

public class Carpet
//  This application performs arithmetic with two integers
  public static void main(String[] args)
    int carpetLength = 14;
    int carpetWidth = 11;
      double carpetPrice = 3.75;
    System.out.print("Length of the carpet is " + carpetLength);
      System.out.print("Width of the carpet is " + carpetWidth);
      System.out.println("Price for square foot is $" + carpetPrice);
      product = carpetLength * carpetWidth;
      System.out.println("Cost for carpeting the room is $" + product * carpetPrice);
Question by:dynamicOne
  • 2
LVL 36

Accepted Solution

mccarl earned 2000 total points
ID: 39475338
You need to inform Java of what "type" your product variable should be, try this...
int product = carpetLength * carpetWidth;

Open in new window

In Java, all variables need to be declared before they can be used.

Author Comment

ID: 39475384
Thank you, I appreciate it!
LVL 36

Expert Comment

ID: 39475484
Not a problem, glad to help!

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question