Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class semifinal {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- menu();
- String choice = sc.nextLine();
- while(true) {
- if(choice.equals("m")) {
- System.out.print("Enter board size: ");
- int size = sc.nextInt();
- makeBoard(size);
- printBoard(makeBoard(size));
- }
- else if(choice.equals("q")) {
- System.out.println("Good bye!");
- }
- }
- }
- public static void menu() {
- System.out.println("q - quit,");
- System.out.println("r - reset,");
- System.out.println("m - make,");
- System.out.println("a - add queen,");
- System.out.println("d - delete queen,");
- System.out.println("c - count queen,");
- System.out.println("p - print board\n");
- System.out.print("Enter option: ");
- }
- public static int[][] makeBoard(int size){
- int[][] board = new int[size][size];
- for(int i = 0;i<board.length;i++) {
- for(int j=0; j<board.length;j++) {
- board[i][j]=' ';
- }
- }
- return board;
- }
- public static void printBoard(int[][] board) {
- for(int i = 0;i<board.length;i++) {
- for(int j=0; j<board.length;j++) {
- board[i][j]=' ';
- }
- }
- int size = board.length;
- for(int i=0;i<=size;i++) {
- if(i==0) {
- System.out.printf("%4s|"," ");
- }else {
- if(i<10) {
- System.out.printf(" "+i+" |");
- }else {
- System.out.printf(" "+i+" |");
- }
- }
- }
- System.out.println();
- System.out.println(dashes(size));
- for(int i = 0; i<size;i++) {
- System.out.printf("| "+(i+1));
- for(int j = 0; j<size;j++) {
- System.out.printf(" |"+board[i][j]+"");
- }
- System.out.println(" |");
- System.out.println(dashes(board.length));
- //System.out.println();
- }
- }
- public static String dashes(int size) {
- String dashes = "";
- for(int l = 0; l<=4*size+3; l++) {
- dashes+="-";
- }
- return dashes;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement