import java.util.Random; import java.util.Scanner; public class LearningGame{ public static void rules() { System.out.println ("There are ten matches at the start"); System.out.println ("On each turn, you should remove either 1 or 2 matches"); System.out.println ( "The computer will respond accordingly"); System.out.println ("After each turn, you will see the number of matches remaining"); System.out.println ("Whoever selects the last match loses"); } public static void main (String args[]) { rules(); Scanner sc = new Scanner(System.in); Scanner sc1 = new Scanner (System.in); Random r = new Random(); int a[] = new int [10]; int b[] = new int[10]; for (int i = 0; i < 10; i++){ a[i] = 0; b[i] = 0; } String status = "yes"; int total = 10, comp = 0, selection = 0; System.out.println (); System.out.println ("START GAME"); System.out.println (); System.out.println ("Match Sticks on The Table = " + total); while (status.equals("yes")){ boolean flag = true; int k = 0; while (flag) { if (total > 1) { boolean flag1 = true; while (flag1) { System.out.println("Your Choice - Select 1 or 2"); selection = sc.nextInt(); if (selection != 1 && selection!= 2){ System.out.println ("Illegal Selection - Has to be 1 or 2"); } else{ flag1 = false; } } total -= selection; System.out.println ("Matches left after your choice = " + total); } if (total == 0 ) { System.out.println ("Computer Won"); flag = false; for (int i = 0; i a[total - 2]) { comp = 1; } else { comp = 2; } System.out.println ("Computer's Choice - " + comp); b[k] = total - comp; k++; total -= comp; System.out.println ("Matches left after computer' choice = " + total); System.out.println(); System.out.print ("Computer's Choices so Far in this Game : "); for (int j = 0; j