所以,现在我编辑的代码,当有四个时,计算行中的头数和五个连续时的头数。我有以下代码可以正确运行,但它只计算四个数字而不是五个数字。谁能帮我?我复制并粘贴了我的代码之后运行的结果。硬币翻转代码 - 试图数出字符串输出
public class Flip {
public static void main(String[] args)
{
final int FLIPS = 100;
int heads = 0;
int consecCountfour = 0;
int consecCountfive = 0;
System.out.println("Trail Tosses:");
for (int i = 1; i<= FLIPS; i++)
{
if (Math.random() < 0.5) {
System.out.print("h");
heads++;
}
else {
System.out.print("t");
if (heads == 4) { consecCountfour++; }
heads = 0;
if (heads == 5) { consecCountfive++; }
heads = 0;
}
}
System.out.println("\n");
System.out.print("Count hhhh:"+ consecCountfour);
System.out.print(" Count hhhhh:" + consecCountfive);
}
}
'诠释头= 0;'硬币过来的头:'首长++;' – Laurel
你需要一些变量与第一 –
算我怎么能做出HS和TS可数如果是有道理的?我需要写些什么才能使结果成为字符串 – Alex