I am working on a java assignment where I have to get BMI with dialog boxes. I keep getting this error "error: illegal start of expression if (BMI = > 18.5 && BMI < 24.9) " Here is the code. Can someone please help!?

import javax.swing.JOptionPane;

public class BodyMassIndex

{

        public static void main(String[]args)

        {

                String input;

                double height;

                double weight;

                double bodyMassIndex = 100;

                // Prompt the user for a weight.
                input = JOptionPane.showInputDialog("What is your weight ");
                weight = Double.parseDouble(input);

                // Prompt the user for a height.
                input = JOptionPane.showInputDialog("What is your height ");
                height = Double.parseDouble(input);

                bodyMassIndex = (weight * 703)/(height * height);

                // Determine whether the user is Optimal, Under, or Overweight.

                if (BMI = > 18.5 && BMI < 24.9)
                {
                    JOptionPane.showMessageDialog(null, "You are Optimal weight " + "Your BMI is " + BMI);
                }
                else if (BMI < 18.5)
                {
                    JOptionPane.showMessageDialog(null, "You are underweight" + "Your BMI is " + BMI);
                }
                else
                {
                    JOptionPane.showMessageDialog(null, "You are overweight " + "Your BMI is " + BMI);
                }

                System.out.println("BodyMassIndex ");


        }

}

hai BoDuke1835

i think you are operation form is not like this

if (BMI = > 18.5 && BMI < 24.9)

i guess its like this

if (BMI >= 18.5 && BMI < 24.9)

try to change it as above

check it once

let me know the status

it should be if((BMI >= 18.5) && (BMI < 24.9)){}
And its always a good idea to use round brackets in you if statements as the compiler can be a bit of an anoyance sometimes

brilliant. did either of you look at the code?
there are two problems in his/her code:

  1. the operator should be >=, not = >
    but, and here's the kicker:
  2. you don't have a variable called BMI. so, either rename your variable, or rename the variable you test on.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.