我曾尝试将整数变成一个字符串,然后像那样拆分它,但后来我得到一个错误,因为我必须乘以那个字符串,但显然我不能。这是我的代码。
import java.util.Scanner;
public class BMI {
public static void main(String[] args) {
Scanner BMI1 = new Scanner(System.in);
Scanner BMI2 = new Scanner(System.in);
Scanner BMI3 = new Scanner(System.in);
String name;
int weightPounds;
int heightFtInches;
int heightInches;
double weightKg;
double heightM;
System.out.print("Please enter your name (e.g. First Last): ");
name = BMI1.nextLine();
System.out.print("Please enter your weight in pounds (e.g. 150): ");
weightPounds = BMI2.nextInt();
System.out.print("Please enter your height in feet and inches (e.g. 6, 8): ");
heightFtInches = BMI3.nextLine();
String[] token = heightFtInches.split(",");
System.out.println();
System.out.println("Body Mass Index Calculator");
System.out.println("#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#");
System.out.println();
weightKg = weightPounds / 2.2;
heightInches = heightFtInches * 12;
System.out.println("Name: " + name);
System.out.println("Weight in Kg: " + weightKg);
System.out.println("Height in meters: " + heightInches);
}
}