Write a method to return true if tic-tac-toe winner | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Write a method to return true if tic-tac-toe winner

If anyone has the shortest solution for this, please share. I’m so new here, by the way.

6th Sep 2019, 3:59 AM
Sothey Sean
Sothey Sean - avatar
2 Answers
+ 4
You could use ternary looks somthing like this. int player1 = 1; int player2 = 0; boolean b = player1>player2?true:false; String result = b?"won":"lost"; System.out.println("you "+result+" this game");
6th Sep 2019, 8:11 AM
D_Stark
D_Stark - avatar
0
i’m looking for a boolean method to return true if win, my way is to write all scenarios winning case of all rows and columns for each player, but i think there should be a shortest way
7th Sep 2019, 3:12 AM
Sothey Sean
Sothey Sean - avatar