Advertisement
Shavit

P. 39 Ex. 10.16

Dec 31st, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. // Shavit Borisov
  2. // CW
  3.  
  4. import java.util.Scanner;
  5.  
  6. public class MineBoardGame {
  7.  
  8.     public static void main(String[] args)
  9.    
  10.     {
  11.         Scanner in = new Scanner (System.in);
  12.        
  13.         final int BOARD_SIZE = 10;
  14.        
  15.         boolean[] board = new boolean[BOARD_SIZE];
  16.         int pawn;
  17.        
  18.         System.out.println("Enter the board details: Type F for a cell with a mine, and T for a free cell: ");
  19.        
  20.         for(int i = 0; i < BOARD_SIZE; i++)
  21.         {
  22.             System.out.printf("Enter status of cell number %d: ", i + 1);
  23.             board[i] = (in.nextLine().charAt(0) == 'T');
  24.         }
  25.        
  26.         System.out.print("Enter the pawn position: ");
  27.         pawn = in.nextInt() - 1;
  28.        
  29.         System.out.println("Throws that lead to empty positions: ");
  30.         for(int i = 1; i <= 6; i++)
  31.             if(board[pawn + i])
  32.                 System.out.printf("%d ==> Cell No. %d\n", i, pawn + i);
  33.        
  34.         in.close();
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement