Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Numerical Tic Tac Toe Uses numbers instead of X and O. Winner is declared when a line = 15. I have string input from users

Numerical Tic Tac Toe

Uses numbers instead of X and O. Winner is declared when a line = 15.

I have string input from users that supposed to display on 2d array of buttons. Want to convert string input into integers so that i add up rows and columns.

When checking for a winning row or column I try to convert the input into an integer array but my app crashes.

 private boolean checkForWin() { String answer = "15"; String[][] field = new String[3][3]; for(int i = 0; i < 3; i++) { for(int j = 0; j < 3; j++) { field[i][j] = buttons[i][j].getText().toString(); } } boolean winnerCheck = false; /* int answer = 15; Integer[][] field = new Integer[3][3]; for(int i = 0; i < 3; i++) { for(int j = 0; j < 3; j++) { field[i][j] = Integer.parseInt(buttons[i][j].getText().toString()); } } */ for (int i = 0; i < 3; i++) { if(field[i][0] + field[i][1] + field[i][2] == answer) { winnerCheck = true; } } for (int i = 0; i < 3; i++) { if((field[0][i]) + (field[1][i]) + (field[2][i]) == answer) { winnerCheck = true; } } if((field[0][0]) + (field[1][1]) + (field[2][2]) == answer) { winnerCheck = true; } if((field[0][2]) + (field[1][1]) + (field[2][0]) == answer) { winnerCheck = true; } return winnerCheck; } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions