Welcome to Dream.In.Code
Become a Java Expert!

Join 150,413 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 976 people online right now. Registration is fast and FREE... Join Now!




Cannot find symbol error: did I forget something?

 
Reply to this topicStart new topic

Cannot find symbol error: did I forget something?

ibleedart
2 Apr, 2008 - 07:13 PM
Post #1

New D.I.C Head
*

Joined: 3 Oct, 2007
Posts: 6


My Contributions
I can't seem to find what I'm doing wrong. I looked in my text book to see if I could find the reason I'm getting this error with no luck. Any help would be greatly appreciated! smile.gif
Full code (a short program)
CODE

import java.util.*;

public class Convert
{
  static Scanner console = new Scanner(System.in);

  static final double cmToInches = 2.54;

  public static void main (String[] args)
  {
    //declare variables
    int yourInches, yardLength, yourLength, yourFeet, remInches;
    double inchLength, feetLength;

    //output prompt and get user input
    System.out.print("Please enter a length in centimeters: ");
    System.out.flush();

    yourLength = console.nextInt();
    
    //convert centimeters to nearest inch
    inchLength = yourLength/cmToInches;
     yourInches = round (inchLength);

    //output the results in whole inch
    System.out.println();
    System.out.println("Your centimeters converted to the nearest whole inch is "
                     + yourInches);

    //complete remaining conversions
    System.out.println();
    yardLength = yourInches/36;
    yourYards = yardLength;
    feetLength = ((yourInches/36) - yardLength)*3;
    remInches = yourInches - ((yourFeet*12) + (yourYards*36));

    //output final conversion results
    System.out.println("Your inches equals: " + yourYards + " yard(s), " + yourFeet +
                      " feet(foot), and " + remInches + " inches.");

  }
}


The first compile error starts with this line:
CODE

     yourInches = round (inchLength);


and the error says "cannot find symbol".
User is offlineProfile CardPM
+Quote Post

GWatt
RE: Cannot Find Symbol Error: Did I Forget Something?
2 Apr, 2008 - 07:15 PM
Post #2

human inside
Group Icon

Joined: 1 Dec, 2005
Posts: 2,360



Thanked: 31 times
Dream Kudos: 500
My Contributions
you need to say Math.round(inchLength)
you can't call java methods like c functions unless the method is in the class from which you are calling the method.
User is online!Profile CardPM
+Quote Post

fsloke
RE: Cannot Find Symbol Error: Did I Forget Something?
2 Apr, 2008 - 11:02 PM
Post #3

D.I.C Regular
***

Joined: 19 Dec, 2007
Posts: 258



Thanked: 4 times
My Contributions
Yes, Math.round(inchLength)

Cannot Found the Symbol "round". That why the error come out...
User is offlineProfile CardPM
+Quote Post

pbl
RE: Cannot Find Symbol Error: Did I Forget Something?
3 Apr, 2008 - 03:59 AM
Post #4

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
Math.round(double)

returns a long
if you want to put it in a int you need to cast it

CODE

yourInches = (int) Math.round (inchLength);


BTW the variable yourYards is not defined.

This post has been edited by pbl: 3 Apr, 2008 - 04:05 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 07:50PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month