Results 1 to 6 of 6
  1. #1
    Nigel is offline Member
    Join Date
    Mar 2011
    Posts
    8
    Rep Power
    0

    Default Illegal start of expression

    Hi

    I'am adding the method printBMI to a class with the following code:

    public void drukBMI()
    {
    double result;
    result = (weight/height**2);
    System.out.println ( "This person's BMI is" + result );
    }

    but when I compile he selects the line result = .....
    "illegal start of expression"
    how do I fix it?

  2. #2
    BiteMuncher's Avatar
    BiteMuncher is offline Member
    Join Date
    Feb 2011
    Location
    South Africa
    Posts
    51
    Rep Power
    0

    Default

    I think the problem is you have two multiplying characters after the other.
    Sorry, I only speak machine language. Yes or a No?:confused:

  3. #3
    Nigel is offline Member
    Join Date
    Mar 2011
    Posts
    8
    Rep Power
    0

    Default

    Isn't it the same as height*height?

  4. #4
    BiteMuncher's Avatar
    BiteMuncher is offline Member
    Join Date
    Feb 2011
    Location
    South Africa
    Posts
    51
    Rep Power
    0

    Default

    No, you can use the Math class.
    weight/Math.pow(height,2)
    The pow method from the Math class is used to get height to the power of 2 which is the same as (height * height).
    Sorry, I only speak machine language. Yes or a No?:confused:

  5. #5
    BiteMuncher's Avatar
    BiteMuncher is offline Member
    Join Date
    Feb 2011
    Location
    South Africa
    Posts
    51
    Rep Power
    0

    Default

    I think height*=height would give the correct answer as well.
    Sorry, I only speak machine language. Yes or a No?:confused:

  6. #6
    Nigel is offline Member
    Join Date
    Mar 2011
    Posts
    8
    Rep Power
    0

Similar Threads

  1. Illegal start of expression
    By Tekila in forum New To Java
    Replies: 10
    Last Post: 03-04-2011, 12:23 AM
  2. illegal start of expression
    By rajivjoshi in forum New To Java
    Replies: 3
    Last Post: 05-31-2010, 09:12 AM
  3. Illegal Start of expression
    By Macca07 in forum New To Java
    Replies: 3
    Last Post: 11-23-2009, 08:43 AM
  4. Illegal start of expression
    By Basit56 in forum New To Java
    Replies: 2
    Last Post: 08-18-2009, 09:12 AM
  5. Illegal start of expression
    By gabriel in forum New To Java
    Replies: 2
    Last Post: 08-01-2007, 05:09 PM

Posting Permissions

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