It seems like the issue lies in how you're trying to parse the input string for height and weight. The error message suggests that it's having trouble converting the string "1.72 59" into a number, likely because it's expecting just one number rather than two separated by a space.
Here's a revised version of your code that should work:
```java
import javax.swing.JOptionPane;
public class Main {
public static void main(String[] args) {
String input = JOptionPane.showInputDialog("Enter height and weight (separated by a space):");
// Split the input string into height and weight
String[] parts = input.split(" ");
double height = Double.parseDouble(parts[0]);
double weight = Double.parseDouble(parts[1]);
// Calculate BMI
double bmi = calculateBMI(height, weight);
// Display the result
JOptionPane.showMessageDialog(null, "Your BMI is: " + bmi);
}
// Function to calculate BMI
public static double calculateBMI(double height, double weight) {
// Convert height from meters to centimeters
height /= 100;
// Calculate BMI
return weight / (height * height);
}
}
```
This code uses `split()` to separate the input string into two parts (height and weight), then converts them into numbers separately. Also, I've adjusted the BMI calculation logic assuming you want the BMI formula (weight / height^2) based on the metric system (height in meters, weight in kilograms).
Additionally, if you need further
help with your Java assignment or any programming-related tasks, there are resources available online where you can seek guidance. Exploring various programming forums or engaging with online communities dedicated to programming can often provide valuable insights and assistance. Remember, learning programming is a journey, and seeking help when encountering challenges is a natural part of the process. You may also find useful resources on websites like
ProgrammingHomworkHelp.com.