2013-10-22 50 views
-1

我正在編寫一個程序,並試圖計算某些TDEE。每個性別之間的方程不會有所不同。要計算TDEE,你需要考慮他們的活動因子和BMR,並將其乘以我知道如何去做,但活動因子是變化的,並且是我需要幫助的。 O需要知道如何將「如果acLevel1等於0,那麼活動因子爲1.0」放入java中?但是我還需要知道,如果是女性輸入數據,我將如何改變,因爲活動因素因性別而異。我編寫了大部分代碼,但只需要一點點幫助。在Java中創建一個等於另一個值的值

import java.util.Scanner; 
public class TDEE 
{ 
public static void main(String[] args) 
{ 
Scanner TDEE = new Scanner(System.in); 
char gender; 
char acLevel; 
double TDEEReal; 

System.out.println("Enter your First and Last name: "); 
String TDEE1 = TDEE.nextLine(); 

System.out.println("Enter your Basal Metabolic Rate: "); 
double TDEE2 = TDEE.nextInt(); 

System.out.println("Enter your gender (M/F): "); 
String gender1 = TDEE.nextLine(); 
gender = gender1.charAt(0); 
System.out.println(); 

System.out.println("Select your activity level"); 
System.out.println("[0] Resting(Sleeping, Reclining"); 
System.out.println("[1] Sedentary(Minimal Activity"); 
System.out.println("[2] Light(Sitting, Standing)"); 
System.out.println("[3] Moderate(Light manual labor, Dancing, Riding a bike)"); 
System.out.println("[4] Very Active(Team sports, Hard manual labor)"); 
System.out.println("[5] Extremely Active(Full time athlete, Heavy manual labor)"); 
System.out.println(); 

System.out.print("Enter the number corresponding to your activity level: "); 
String acLevel1 = TDEE.nextLine(); 
acLevel = acLevel1.charAt(0); 
System.out.println(); 
+0

和你的代碼中有什麼問題? – exexzian

回答

0

[沒有粗魯的意圖]有沒有聽說過有條件的陳述?如果別的..?

if (acLevel1 == 0) 
{ 
    activityFactor = 1.0 
} 
+0

我有,沒有必要在你的第一句話中粗魯。 –

+0

不完全。 acLevel1是一個字符串,將它與int文字進行比較不會奏效。 AcLevel是一個字符,所以如果(acLevel =='0')。也不需要這麼尖刻,我們都有腦屁。 – Taylor

+0

凱文我沒有被嚇倒。我只是說,當我所做的只是提出一個簡單的java問題時,他不必粗魯,所以我可以學習如何正確地做到這一點。我的問題沒有錯誤?我告訴過你們所有你需要知道的信息,以幫助我學會如何去做。 –

1

問題是,acLevel1是一個字符串,所以你不能以你想要的方式使用它。我會將acLevel1更改爲int並將其更改爲nextInt。

然後使用的if else語句納雷什寫道

 if (acLevel == 0) { 
     activityFactor = 1.0; 
    } 
+0

這應該是'acLevel =='0''? – kevinsa5

+0

此外,您還可以使用.equals方法評估字符串:if(「0」.equals(acLevel1)){}'。 – Radiodef

+0

是的,但沒有使用if語句的布爾值==。 – Mercifies

0

你可以使用一個switch語句給每個條件的,一旦你已經跟着Mercifies'關於使用.nextInt()方法的建議。

相關問題