Created
November 1, 2013 17:36
Revisions
-
joeyv created this gist
Nov 1, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,74 @@ import java.util.*; public class Sticks{ public static void main(String []args){ int sticks, maxStick = 0; int userStick = 0, compStick = 0; Scanner scan = new Scanner(System.in); Random generator = new Random(); sticks = generator.nextInt(80) + 20; if (sticks >= 51){ maxStick = 5; } else if (40 < sticks && sticks <= 50){ maxStick = 4; } else if (30 < sticks && sticks <= 40){ maxStick = 3; } else if (19 < sticks && sticks <= 30){ maxStick = 2; } while (sticks >= 0){ System.out.println ("There is " + sticks + " sticks in the pile."); System.out.println ("Take out 1 - " + "" + maxStick + ":"); userStick = scan.nextInt(); if (maxStick == 5){ compStick = generator.nextInt(5) + 1; } else if (maxStick == 4){ compStick = generator.nextInt(4) + 1; } else if (maxStick == 3){ compStick = generator.nextInt(3) + 1; } else if (maxStick == 2){ compStick = generator.nextInt(2) + 1; } if (userStick > maxStick){ System.out.println ("Please pick a number 1 - " + "" + maxStick); }else { continue; } if (sticks == maxStick){ compStick -= 1; } if (sticks == 2){ compStick = 1; } else { sticks -= userStick; sticks -= compStick; } if ( compStick == userStick){ sticks /= 2; } else { sticks -= userStick; sticks -= compStick; } System.out.println ((userStick) + " " + (compStick)); } } }