永发信息网

参考文件Coin.java ,写一程序查找在100次掷硬币过程中连续heads面朝上的次数。

答案:2  悬赏:30  手机版
解决时间 2021-03-28 18:24
  • 提问者网友:遁入空寂
  • 2021-03-28 00:37
参考文件Coin.java ,写一程序查找在100次掷硬币过程中连续heads面朝上的次数。
最佳答案
  • 五星知识达人网友:躲不过心动
  • 2021-03-28 01:30
public static void main(String[] args) {
final int FLIPS = 100; // number of coin flips

int currentRun = 0; // length of the current run of HEADS
int maxRun = 0; // length of the maximum run so far

// Create a coin object
Coin coin = new Coin();
// Flip the coin FLIPS times
for (int i = 0; i < FLIPS; i++) {
// Flip the coin & print the result
coin.flip();
if(coin.isHeads()){
currentRun++;
}else{
currentRun=0;
}
// Update the run information
if(currentRun>maxRun) maxRun = currentRun;
}

// Print the results
System.out.print("maxRun="+maxRun);
}
全部回答
  • 1楼网友:三千妖杀
  • 2021-03-28 02:50
你是在说明什么
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯