0

我正在尝试在程序中合并 if-else 语句,但我不断收到“错误:';' 预期”消息。但是,即使我添加了;,它也不起作用。

这是代码:

import java.util.Scanner;

public class IdealWeight
{
    public static void main(String[] args)
    {
        final int OVERMEN = 6;
        final int OVERFEMALE = 5;
        final int INCHESINFOOT = 12;

        int feet;
        int inches;
        int totalHeight;
        int idealWeightMale;
        int idealWeightFemale;

        double leewayMale;
        double leewayFemale;
        double minIdealWeightFemale;
        double maxIdealWeightFemale;
        double minIdealWeightMale;
        double maxIdealWeightMale;

        Scanner scan = new Scanner (System.in);

        System.out.println("Consider your height in imperial units. Break it up into feet and inches.");
        System.out.println("Enter your height in feet.");

        feet = scan.nextInt();

        System.out.println("Enter the remaining inches."); 

        inches = scan.nextInt();

        System.out.println("You entered your height as: " + feet + " feet " + inches + " inches");

        totalHeight = (feet * INCHESINFOOT) + inches;

        if (60 > totalHeight)
            {
            idealWeightFemale = ((100 * totalHeight)/60) + (inches * OVERFEMALE));
            idealWeightMale = ((100 * totalHeight)/60) + (inches * OVERMALE));
            }
        else
            {
            idealWeightFemale = (100 + (inches * OVERFEMALE));
            idealWeightMale = (100 + (inches * OVERMEN));
            }

        System.out.println("If you are female, your ideal weight is " + idealWeightFemale + " pounds.");
        System.out.println("If you are male, your ideal weight is " + idealWeightMale + " pounds.");    

        leewayMale = (.15 * idealWeightMale);   
        leewayFemale = (.15 * idealWeightFemale);
        minIdealWeightMale = (idealWeightMale - leewayMale);
        maxIdealWeightMale = (idealWeightMale + leewayMale);
        minIdealWeightFemale = (idealWeightFemale - leewayFemale);
        maxIdealWeightFemale = (idealWeightFemale + leewayFemale);

        System.out.println("However, if you are male and are within " + minIdealWeightMale + " and " + maxIdealWeightMale + " you are at a healthy weight.");
        System.out.println("However, if you are female and are within " + minIdealWeightFemale + " and " + maxIdealWeightFemale + " you are at a healthy weight.");


    }
}

这样做的目标是让它适用于 5 英尺以下的人,而无需更改任何其他内容。这是错误消息:

    IdealWeight.java:47: error: ';' expected
            idealWeightFemale = ((100 * totalHeight)/60) + (inches * OVERFEMALE));
                                                                                ^
IdealWeight.java:48: error: ';' expected
            idealWeightMale = ((100 * totalHeight)/60) + (inches * OVERMALE));
                                                                            ^
4

3 回答 3

4

您在此行中有一个额外的“)”

idealWeightFemale = ((100 * totalHeight)/60) + (inches * OVERFEMALE));

将其更改为

idealWeightFemale = ((100 * totalHeight)/60) + (inches * OVERFEMALE);

类似的idealWeightMale = ((100 * totalHeight)/60) + (inches * OVERMALE));

于 2012-10-12T04:45:36.597 回答
0

((100 * totalHeight)/60) + (inches * OVERFEMALE)))你在这里和下一行有一个额外的结束括号。将其更改为((100 * totalHeight)/60) + (inches * OVERFEMALE),它编译得很好。

于 2012-10-12T04:47:27.060 回答
0

尝试使用以下代码

idealWeightFemale = ((100 * totalHeight)/60) + (inches * OVERFEMALE);

idealWeightMale = ((100 * totalHeight)/60) + (inches * OVERMALE);

于 2012-10-12T05:17:42.697 回答