Print five-word chess

Source: Internet
Author: User

public class Gobang {
Define a two-dimensional array to act as a chessboard
Private String [] board;
Define Checkerboard Size
private static int board_size = 15;
public void Initborad () {
Board=new String[board_size][board_size];
Assign each element "+" to draw a chessboard in the console
for (int i =0;i<board_size;i++) {
for (int j=0;j<board_size;j++) {
board[i][j]= "+";
}
}
}
How to output a checkerboard in the console

public void Printborad () {
Assign each element "+" to draw a chessboard in the console
for (int i =0;i<board_size;i++) {
for (int j=0;j<board_size;j++) {
Print array elements without wrapping
System.out.print (Board[i][j]);
}
Outputs a newline character after each line of array elements is printed
System.out.println ();
}
}
public static void Main (string[] args) throws IOException {
Gobang GB = new Gobang ();
Gb.initborad ();
Gb.printborad ();
This is the method for getting keyboard input
BufferedReader br = new BufferedReader (new InputStreamReader (system.in));
String Inputstr=null;
Whenever you enter a line of content on the keyboard and press ENTER, the content you just entered will be read by BR to
String text =br.readline ();
System.out.println (text);
while ((Inputstr=br.readline ())!=null) {
Separates the user-entered string into 2 strings with a comma (,) as a delimiter
String [] Possstrarr =inputstr.split (",");
Converts 2 strings to the coordinates of a user's chess game
int XPos =integer.parseint (possstrarr[0]);
int YPos =integer.parseint (possstrarr[1]);
The corresponding array element is assigned the ""
Gb.board[xpos][ypos]= "";
Gb.printborad ();
System.out.println ("Please enter the coordinates of your chess, should be in X, y format:");
}
}

}

Print five-word chess

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.