Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package JavaPackage;
- import java.util.*;
- public class TicTacToe {
- static boolean repeat = true;
- private static int turns;
- static Scanner input = new Scanner(System.in);
- public static void main(String[] args) {
- String[][] board = new String[3][3];
- for (int x = 0; x < 3; x++) {
- for (int y = 0; y < 3; y++) {
- board[x][y] = "|_|";
- System.out.print(board[x][y]);
- }
- System.out.println();
- }
- while (repeat) {
- numpick(board);
- }
- }
- private static String[][] numpick(String[][] board) {
- int pinput = input.nextInt();
- turns++;
- String player="";
- if(turns%2==1) {
- player="|X|";
- }else {
- player="|O|";
- }
- if (pinput == 7) {
- board[0][0]=player;
- } else if (pinput == 8) {
- board[0][1]=player;
- } else if (pinput == 9) {
- board[0][2]=player;
- } else if (pinput == 4) {
- board[1][0]=player;
- } else if (pinput == 5) {
- board[1][1]=player;
- } else if (pinput == 6) {
- board[1][2]=player;
- } else if (pinput == 1) {
- board[2][0]=player;
- } else if (pinput == 2) {
- board[2][1]=player;
- } else if (pinput == 3) {
- board[2][2]=player;
- }
- for (int x = 0; x < 3; x++) {
- for (int y = 0; y < 3; y++) {
- System.out.print(board[x][y]);
- }
- System.out.println();
- }
- return board;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement