Results 1 to 6 of 6
  1. #1
    bulbul is offline Member
    Join Date
    Nov 2011
    Posts
    3
    Rep Power
    0

    Default can someone check this program to see if its ok. Im having some trouble compiling it.

    Java Code:
    import java.util.Scanner;
    class FeetToMeters{
    
    
    	public static void main(String[] args) {
    
    	
    	Scanner input = new Scanner(System.in);
    	double feet, meters;
    
    	
    	System.out.println("Enter feet");
    	feet = input.nextDouble();
    	meters = (meters * 0.305);
    	System.out.println(feet + " feet is " + meters + " meters");
    
    
         }
    
    }
    Last edited by Fubarable; 11-13-2011 at 04:32 PM. Reason: code tags added

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: can someone check this program to see if its ok. Im having some trouble compiling

    Hello, and welcome to Java-Forums.
    Moderation: code tags added to your original post so we can read the code.

    Please post your full error messages so we can know what the compiler is complaining about.

    Also, look carefully at your code below. Are you sure that the second line is how you should be calculating meters?

    Java Code:
    	feet = input.nextDouble();
    	meters = (meters * 0.305); // meters on both sides of this statement?

  3. #3
    Cosmos is offline Member
    Join Date
    Jul 2011
    Location
    New Delhi,India
    Posts
    56
    Rep Power
    0

    Default Re: can someone check this program to see if its ok. Im having some trouble compiling

    the error is in line 14....

    you are using meters without initializing it....

    it should be something like-

    meters=feet*0.305;

  4. #4
    bulbul is offline Member
    Join Date
    Nov 2011
    Posts
    3
    Rep Power
    0

    Default Re: can someone check this program to see if its ok. Im having some trouble compiling

    oh thankyou

    and another thing, when writing the formula are spaces meant to be left? like e.g 3 * 4 or should it be 3*4?

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: can someone check this program to see if its ok. Im having some trouble compiling

    Quote Originally Posted by bulbul View Post
    and another thing, when writing the formula are spaces meant to be left? like e.g 3 * 4 or should it be 3*4?
    I prefer to have spaces between math operators, and I think that this is also recommended in most Java programming style guidelines, but ultimately, your program style should be based on your instructor's requirements.

  6. #6
    bulbul is offline Member
    Join Date
    Nov 2011
    Posts
    3
    Rep Power
    0

    Default Re: can someone check this program to see if its ok. Im having some trouble compiling

    ok thanks!

Similar Threads

  1. Trouble Compiling
    By winterkid09 in forum New To Java
    Replies: 10
    Last Post: 11-22-2010, 07:26 AM
  2. Trouble compiling java files
    By winterkid09 in forum Java Applets
    Replies: 2
    Last Post: 11-21-2010, 11:25 AM
  3. hi the program is compiling but not running why
    By javastuden in forum New To Java
    Replies: 6
    Last Post: 09-21-2010, 10:14 AM
  4. compiling trouble
    By capacitator in forum CLDC and MIDP
    Replies: 4
    Last Post: 06-10-2008, 11:12 PM
  5. Trouble compiling code
    By waelhelbawi in forum New To Java
    Replies: 1
    Last Post: 05-12-2008, 05:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •