2014-04-20 39 views
1

我已經做了一個代碼女巫問你問題,對於每一個問題你得到正確它增加了一點,問題是我想知道如何顯示你的分數。就像你有多少點一起。如何製作積分,然後將它們全部加起來

System.out.println("#1: What is 8+8?"); 
answer=in.nextInt(); 
if (answer == 16)   
    System.out.println("Correct!"); 
else 
    System.out.println("Incorrect!"); 
if (answer == 16) 
    points =+ 1; 

這是表示,如果「答案」是正確的它會+1點的例子。當它告訴你,你有多少點是正確的,我想要。例如:!「!糾正你現在有‘點’點(S) 這裏是我的整數,如果你需要他們

int points; 
int answer2; 
int answer; 

我只有2個問題,到目前爲止,因爲我等待這個解決方案

回答

0

保持計數器變量,將持有正確答案的數量。

Integer scoreCount = 0; //initial score 

if (answer == 16) { 
    scoreCount += 1; //increase score count   
    System.out.println("Correct! You now have " + scoreCount + " points"); //show latest score 
}  
+0

哦,謝謝!其他人的答案工作,但我無法弄清楚如何保持這個數字!非常感謝sooo! –

3
System.out.println("Correct! You now have "+points+" points!"); 
+0

太謝謝你了!我知道這是類似的東西,只是不知道到底。 –

+0

沒問題!它會如果你能把我標記爲你的問題的答案,那就太好了。 :) –

相關問題