2012-10-12 29 views
0

我想在程序中加入if-else語句,但我總是收到「error:';'預期「消息。但是,即使我添加了,它也不起作用。錯誤:;預計,但在哪裏?

下面是代碼:

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)); 
                      ^
+0

有1個額外Paranthesis在你的聲明在結尾處添加; – gks

+0

有一個額外的')' – pratZ

回答

4

你有一個額外的 「)」 在這一行

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

將其更改爲

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

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

+0

,可以作爲評論 – Abubakkar

+2

@阿布如果它解決OP的問題,那麼它是一個答案:)。我瞭解到,在回答評論和丟失代表的OP時。 –

+0

好吧然後它解決了這個問題,但什麼是「OP」 – Abubakkar

0

((100 * totalHeight)/60) + (inches * OVERFEMALE))你有在這裏和下一行添加一個末端括號)。將其更改爲((100 * totalHeight)/60) + (inches * OVERFEMALE)並編譯好。

0

嘗試用下面的代碼

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

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