Runs - Coin myCoin = new Coin(); // Flip the coin FLIPS...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
//********************************************************************** // Runs.java // // Finds the length of the longest run of heads in 100 flips of a coin. //********************************************************************** public class Runs { 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
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Coin myCoin = new Coin(); // Flip the coin FLIPS times for (int i = 0; i < FLIPS; i++) { // Flip the coin & print the result myCoin.flip(); System.out.println (myCoin); // Update the run information if (myCoin.getFace() == myCoin.HEADS) { currentRun++; if (currentRun > maxRun) maxRun = currentRun; } else currentRun = 0; } // Print the results System.out.println ("The longest run was " + maxRun + " heads in a row."); } }...
View Full Document

This note was uploaded on 03/22/2010 for the course CS 202 taught by Professor Fong during the Spring '10 term at SIU Carbondale.

Ask a homework question - tutors are online