Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class NimGame {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- // System.out.println("Who starts 1 or 2");
- // int x = scan.nextInt();
- // if (x==1){
- int matches = 21;
- while (matches>=0){
- System.out.println("p1 how many would you like to take?");
- int take = scan.nextInt();
- while(take>3 || take<1){
- System.out.println("p1 how many would you like to take this time not more then 3?");
- take = scan.nextInt();
- }
- matches= matches-take;
- System.out.println(matches+" matches left");
- if(matches==0){
- System.out.println("p1 win");
- break;
- }
- System.out.println("p2 how many would you like to take?");
- int take1 = scan.nextInt();
- while(take1>3 || take1<1){
- System.out.println("p2 how many would you like to take this time not more then 3?");
- take1 = scan.nextInt();
- }
- matches= matches-take1;
- System.out.println(matches+" matches left");
- if(matches==0){
- System.out.println("p2 win");
- break;
- }
- }
- }
- // else {
- // int matches1=21;
- // while (matches1>=0){
- // System.out.println("p2 how many would you like to take? ");
- // int take = scan.nextInt();
- // matches1= matches1-take;
- // System.out.println(matches1+" matches left");
- // if(matches1==0){
- // System.out.println("p2 win");
- // break;
- // }
- // System.out.println("p1 how many would you like to take? ");
- // int take1 = scan.nextInt();
- // matches1= matches1-take1;
- // System.out.println(matches1+" matches left");
- // if(matches1==0){
- // System.out.println("p1 win");
- // break;
- // }
- // }
- // }
- // }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement