Java 如何提出观点,然后把它们全部加起来

Java 如何提出观点,然后把它们全部加起来,java,eclipse,points,Java,Eclipse,Points,我做了一个密码,巫婆会问你问题,你每答对一个问题,它就会加一分,问题是我想知道如何显示你的分数。比如你一共有多少分 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) p

我做了一个密码,巫婆会问你问题,你每答对一个问题,它就会加一分,问题是我想知道如何显示你的分数。比如你一共有多少分

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分。我想知道当它告诉你你有多少点是正确的。示例:“正确!您现在有“点”点! 如果你需要的话,这是我的建议

int points;
int answer2;
int answer;

到目前为止,我只有2个问题,因为我正在等待此解决方案。

保留一个计数器变量,该变量将保存正确答案的数量

System.out.println("Correct! You now have "+points+" points!");
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
}    

非常感谢!我知道是那样的,只是不知道确切的数字。没问题!如果你能把我作为你问题的答案,那就太好了。:)哦,老兄,谢谢!其他人的答案奏效了,但我不知道如何保持数字。非常感谢!