//Nim.java class Nim { public static void main(String[] agrs) { String h = "human"; String c = "computer"; int take, matches, player; matches = 11; player = 0; System.out.println("WELCOME TO THE GAME OF NIM"); while((matches > 0)&&(matches != 1)){ if(player==0){ System.out.print("\nHow many matches do you want? "); take = SavitchIn.readLineInt(); if((take < 1)||(take > 3)){ while((take < 1)||(take > 3)){ System.out.print("\nOnly 1, 2 or 3 can be taken: "); take = SavitchIn.readLineInt(); } } } else{ switch(matches){ case 2: take = 1;break; case 3: take = 2;break; case 4: take = 3;break; case 6: take = 1;break; case 7: take = 2;break; case 8: take = 3;break; case 9: take = 1;break; case 10: take = 1;break; default: take = 1+(int)(3*Math.random());break; } } matches = matches - take; switch(player){ case 0: System.out.print("\nThe "+h);player=1;break; case 1: System.out.print("\nThe "+c);player=0;break; } System.out.print(" takes "+take); switch(take){ case 1: System.out.print(" match, ");break; default: System.out.print(" matches, ");break; } System.out.print("leaving "+matches+".\n"); if(matches == 1){ switch(player){ case 0: System.out.print(c+" wins!");break; case 1: System.out.print(h+" wins!");break; } }else{ if(matches == 0){ switch(player){ case 0: System.out.print(h+" wins!");break; case 1: System.out.print(c+" wins!");break; } } } }//end while } }