Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Nim
- {
- public static void main(String[] args)
- { Scanner scan = new Scanner(System.in); //to scan input
- System.out.println ("Welcome to the game of Nim!");
- System.out.println ("The game begins with a heap containing from 10 to 20 stones. Two players take turns to remove from 1 to 4 stones from the heap. The player who removes the last stone wins.");
- int heapSize = (int)((Math.random() * 20) + 10);
- boolean player1 = true;
- while (heapSize > 0)
- {
- System.out.println ("The heap contains " + heapSize + "stones" + PLAYER (see mis muutuma peab iga kord) + " choose how many stones you want to remove (1-4)");
- int input = scan.nextInt();
- heapSize = heapSize - input;
- if (heapSize > 0)
- {
- player1 = false;
- }
- } System.out.println ("The winner is " + player (peab teadma, kumb viimasena v6ttis) + "!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement