Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- public class Main {
- public static void main(String[] args) {
- Random random = new Random();
- char[][] mat = new char[3][3];
- for(int i = 0; i < 3; i++) {
- for(int j = 0; j < 3; j++) {
- int r = random.nextInt(100);
- if(r % 2 == 0) {
- mat[i][j] = 'O';
- }
- else {
- mat[i][j] = 'X';
- }
- }
- }
- for(int i = 0; i < 3; i++) {
- for(int j = 0; j < 3; j++) {
- System.out.print(mat[i][j]);
- }
- System.out.println();
- }
- String winner = "No winner";
- if(mat[0][0] == 'X' && mat[0][1] == 'X' && mat[0][2] == 'X') {
- winner = "X";
- }
- if(mat[0][0] == 'O' && mat[0][1] == 'O' && mat[0][2] == 'O') {
- winner = "O";
- }
- if(mat[1][0] == 'X' && mat[1][1] == 'X' && mat[1][2] == 'X') {
- winner = "X";
- }
- if(mat[1][0] == 'O' && mat[1][1] == 'O' && mat[1][2] == 'O') {
- winner = "O";
- }
- if(mat[2][0] == 'X' && mat[2][1] == 'X' && mat[2][2] == 'X') {
- winner = "X";
- }
- if(mat[2][0] == 'O' && mat[2][1] == 'O' && mat[2][2] == 'O') {
- winner = "O";
- }
- if(mat[0][0] == 'X' && mat[1][0] == 'X' && mat[2][0] == 'X') {
- winner = "X";
- }
- if(mat[0][0] == 'O' && mat[1][0] == 'O' && mat[2][0] == 'O') {
- winner = "O";
- }
- if(mat[0][1] == 'X' && mat[1][1] == 'X' && mat[2][1] == 'X') {
- winner = "X";
- }
- if(mat[0][1] == 'O' && mat[1][1] == 'O' && mat[2][1] == 'O') {
- winner = "O";
- }
- if(mat[0][2] == 'X' && mat[1][2] == 'X' && mat[2][2] == 'X') {
- winner = "X";
- }
- if(mat[0][2] == 'O' && mat[1][2] == 'O' && mat[2][2] == 'O') {
- winner = "O";
- }
- if(mat[0][0] == 'X' && mat[1][1] == 'X' && mat[2][2] == 'X') {
- winner = "X";
- }
- if(mat[0][0] == 'O' && mat[1][1] == 'O' && mat[2][2] == 'O') {
- winner = "O";
- }
- if(mat[0][2] == 'X' && mat[1][1] == 'X' && mat[2][0] == 'X') {
- winner = "X";
- }
- if(mat[0][2] == 'O' && mat[1][1] == 'O' && mat[2][0] == 'O') {
- winner = "O";
- }
- System.out.println("The winner is: " + winner);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement