Simple Java Program Error

Discussion in 'Software' started by thagentleman, Dec 15, 2005.

  1. thagentleman

    thagentleman Private E-2

    I am writing a simple java program using Netbeans 5.0 Beta 2 and I keep on getting an error and the program is straight from the book. Her is the program.



    public class ComputeArea
    {
    /**Main method*/
    public static void main(String[] args)
    {
    double radius;
    double area;

    // Prompt the user to enter radius
    System.out.print("Enter radius: ");
    radius = MyInput.readDouble();

    // Compute area
    area = radius*radius*3.14159;

    // Display results
    System.out.println("The area for the circle of radius " +
    radius + " is " + area);
    }
    }
    I keep on getting an error at the radius=MyInput.readDouble();

    It says that it cannot find symbol
    symbol: variable MyInput
    location: class Computearea.Main
     
  2. bytegoddess

    bytegoddess Private E-2

    The variable "MyInput" is probably named something else... this is a common problem one encounters when copying program examples from other sources; it's difficult to remember to substitute your names for the author's ;-)

    Most likely, you have named the text field or area you are using to get user data something other than "MyInput" and you therefore need to change your code to reflect this.

    It's a good hint that when an author creates a code example that includes variable names like MyThis or MyThat, you are supposed to substitute the appropriate variable names you are using in the program.

    I hope this helps.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds