{"id":11939,"date":"2022-10-31T08:44:45","date_gmt":"2022-10-31T08:44:45","guid":{"rendered":"https:\/\/brightchamps.com\/blog\/?p=11939"},"modified":"2024-10-01T10:46:33","modified_gmt":"2024-10-01T10:46:33","slug":"tic-tac-toe-game-in-java","status":"publish","type":"post","link":"https:\/\/brightchamps.com\/blog\/tic-tac-toe-game-in-java\/","title":{"rendered":"How to create a Tic Tac Toe Game in Java"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Almost all of us are familiar with the <strong>tic tac toe game<\/strong>. This strategy game is quite easy to play but kind of challenging to beat the opponent.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Back then we can play this game simply with a piece of paper and pen. Draw a 3&#215;3 grid and start to write down O or X consecutively between two players.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">By developing this tic tac toe game project utilizing several computer languages, we can eventually convert this game to a digital one. We will discuss how to make a tic tac toe game in Java, one of the computer languages that we can use to develop this game.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So, keep on reading, Champs!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-what-is-a-tic-tac-toe-game\">What is a Tic tac toe game?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Tic-tac-toe<\/strong> is a simple strategy game played on a 3&#215;3 grid by two players, who alternately place the marks X and O in one of the nine spaces in the grid. This game is also well-known as <strong>noughts and crosses<\/strong> in Commonwealth English, or <strong>Xs and Os<\/strong> in Canadian or Irish English.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Determining the winner is quite simple actually. The first player who succeeds in placing three of their marks (be it O or X) in a horizontal, vertical, or diagonal row is the winner.<\/p>\n\n\n\n<div id=\"cstm_banner_cta\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-tic-tac-toe-game-in-java\">Tic Tac Toe Game in Java<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Creating console <strong>Tic tac Toe game in Java<\/strong> is deceptively easy and quite simple. It can even be created by beginners. Because actually in this game we are going to practice the basic core concept like:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Variables<\/li>\n\n\n\n<li>Booleans<\/li>\n\n\n\n<li>Input and Output<\/li>\n\n\n\n<li>Conditionals checking<\/li>\n\n\n\n<li>Loops<\/li>\n\n\n\n<li>Functions<\/li>\n\n\n\n<li>2D arrays<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">In this tutorial, we are going to create a simple console <strong>Tic Tac Toe game in Java<\/strong>, in which there will be 2 players taking turn in choosing grid row and column to place their characters.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We are going to use the most basic solution which is accessible and easily understandable by all skill levels in programming.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-how-to-create-tic-tac-toe-game-in-java\">How To Create Tic Tac Toe Game in Java<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Build The Board<\/strong><\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img fetchpriority=\"high\" fetchpriority=\"high\" decoding=\"async\" width=\"794\" height=\"655\" src=\"https:\/\/brightchamps.com\/blog\/wp-content\/uploads\/2022\/10\/Tic-Tac-Toe-Game-in-Java-1.jpg\" alt=\"Tic Tac Toe Game in Java\" class=\"wp-image-11941\" style=\"width:596px;height:491px\" srcset=\"https:\/\/brightchamps.com\/blog\/wp-content\/uploads\/2022\/10\/Tic-Tac-Toe-Game-in-Java-1.jpg 794w, https:\/\/brightchamps.com\/blog\/wp-content\/uploads\/2022\/10\/Tic-Tac-Toe-Game-in-Java-1-480x396.jpg 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 794px, 100vw\" \/><figcaption class=\"wp-element-caption\"><em>Illustration of the game board using 2D arrays<\/em><\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The first step is to create the board by making a 3&#215;3 grid. To create this board we will need 2D array of characters. We are going to use dashes [ &#8211; ] to create our board.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>Hint:<\/em><\/strong><em> <\/em><em>To create a 3&#215;3 char array, use the following line of code:<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em><strong>char[][] gameBoard = new char[3][3]<\/strong><\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To fill our game board with dashes [ &#8211; ], we can use nested loop and set<strong> gameBoard[i][j] = \u2018-\u2018<\/strong>.<\/p>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Ask Both Players\u2019 Name<\/strong><\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">To ensure that our game will be able to get input from user, we need to import <em><strong>java.util.Scanner<\/strong><\/em> at the top of our project.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After we initialize our game board with dashes, we will create the Scanner variable. Next, we will print out the message asking for both players to enter their names. Those names will be stored in a String variable called <strong>player_1 <\/strong>and <strong>player_2<\/strong>.<\/p>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Print Out The Board Like a 3&#215;3 Gridlines<\/strong><\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" width=\"1023\" height=\"608\" src=\"https:\/\/brightchamps.com\/blog\/wp-content\/uploads\/2022\/10\/Tic-Tac-Toe-Game-in-Java-2.jpg\" alt=\"Tic Tac Toe Game in Java\" class=\"wp-image-11942\" style=\"width:767px;height:456px\" srcset=\"https:\/\/brightchamps.com\/blog\/wp-content\/uploads\/2022\/10\/Tic-Tac-Toe-Game-in-Java-2.jpg 1023w, https:\/\/brightchamps.com\/blog\/wp-content\/uploads\/2022\/10\/Tic-Tac-Toe-Game-in-Java-2-980x582.jpg 980w, https:\/\/brightchamps.com\/blog\/wp-content\/uploads\/2022\/10\/Tic-Tac-Toe-Game-in-Java-2-480x285.jpg 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1023px, 100vw\" \/><figcaption class=\"wp-element-caption\"><em>How the game board will look like in the console<\/em><\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">To display the board to the players, we need a function to prints it out with the 2D array as the parameter. We will only print the board with this function, hence there will be no return value from this function.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We can use <strong>System.out.print();<\/strong> and <strong>System.out.println();<\/strong> alternately. To display each column, use <strong>System.out.print(); <\/strong>since it will print it out on one line, and use <strong>System.out.println();<\/strong> to print new row.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>Hint:<\/em><\/strong><em> Use <strong>System.out.print(); <\/strong>in the inner for loop, and use <strong>System.out.println();<\/strong> after the iteration of the inner for loop is finished. Therefore it will start<\/em> a new row after all of the columns in each row have<em> been printed out.<\/em><\/p>\n\n\n\n<ol start=\"4\" class=\"wp-block-list\">\n<li><strong>Keep Track of Correct Player\u2019s Turn and Char (X or O)<\/strong><\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">We can use conditional checking to keep track of whose turn it is, whether it\u2019s player 1 or player 2.<\/p>\n\n\n\n<ol start=\"5\" class=\"wp-block-list\">\n<li><strong>Players Choose Row and Column and We Check The Validity&nbsp;<\/strong><\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Use <strong>System.out.print();<\/strong> to print out a message telling the user to choose the row and column to put their X or O, and use the <strong>Scanner<\/strong> variable to get their input. Their chosen row and column will be stored in the <strong>int<\/strong> variables called <strong>row<\/strong> and<strong> col<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Player\u2019s chosen row and column are not always valid. There are 3 probabilities of their input:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>User entering invalid number that is not on the board (less than 0 or greater than 2).<\/li>\n\n\n\n<li>User choosing row and column that already being blocked by other player (it already has an X or O on it).<\/li>\n\n\n\n<li>User choosing the empty spot on the board (entering valid number between 0 \u2013 2 and there\u2019s no X nor O on it).<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">From all of the above probabilities, our aim is of course the c situation. Therefore we need to use a conditional to check their input.&nbsp;<\/p>\n\n\n\n<div id=\"cstm_banner_cta\"><\/div>\n\n\n\n<ol start=\"6\" class=\"wp-block-list\">\n<li><strong>Use a Loop to Ensure Player Enter a Valid Row and Column<\/strong><\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">We need to keep asking player to re-enter valid row and column number, whenever there\u2019s a situation a or b above. We can use <strong>while(true) <\/strong>and break the loop once the player entered a valid row and column.<\/p>\n\n\n\n<ol start=\"7\" class=\"wp-block-list\">\n<li><strong>Set the Player\u2019s Character on The Right Spot on The Board<\/strong><\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Once we have a valid row and column, now we can put the player\u2019s character on the right spot by writing <strong>gameBoard[row][col] = c;<\/strong> in which <strong>c<\/strong> is a variable that stores the player\u2019s character (X or O).<\/p>\n\n\n\n<ol start=\"8\" class=\"wp-block-list\">\n<li><strong>Create a Function to Checks The Winner<\/strong><\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" width=\"941\" height=\"804\" src=\"https:\/\/brightchamps.com\/blog\/wp-content\/uploads\/2022\/10\/Tic-Tac-Toe-Game-in-Java-3.jpg\" alt=\"Tic Tac Toe Game in Java\" class=\"wp-image-11943\" style=\"width:706px;height:603px\" srcset=\"https:\/\/brightchamps.com\/blog\/wp-content\/uploads\/2022\/10\/Tic-Tac-Toe-Game-in-Java-3.jpg 941w, https:\/\/brightchamps.com\/blog\/wp-content\/uploads\/2022\/10\/Tic-Tac-Toe-Game-in-Java-3-480x410.jpg 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 941px, 100vw\" \/><figcaption class=\"wp-element-caption\"><em>Illustration of all possible winning combination<\/em><\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">A player wins if their three characters appear in a row, column, or diagonal.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In our Java Tic Tac Toe game, we can utilize <strong>if<\/strong> conditional testing inside <strong>for<\/strong> loop to determine the winner.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s say we check the row first, we can iterate through each row <strong>i<\/strong>. If <strong>gameBoard[i][0]<\/strong> equals <strong>gameBoard[i][1] <\/strong>and if <strong>gameBoard[i][1]<\/strong> equals <strong>gameBoard[i][2] <\/strong>and <strong>gameBoard[i][0]<\/strong>&nbsp; doesn\u2019t equal to a dash or in another word, there\u2019s no empty spot, then we have the winner and we can return the value of <strong>gameBoard[i][0]<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Similar steps can be used as well to check the column result.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If none of the conditions were true and we reach the end of our function, it means that there\u2019s no winner and we can just return a whitespace.<\/p>\n\n\n\n<ol start=\"9\" class=\"wp-block-list\">\n<li><strong>If There\u2019s a Winner, Print Out The Player who Win<\/strong><\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">In the previous function that checks the whether there\u2019s a winner, there\u2019s a return value. So in our main method, we can use <strong>if<\/strong> conditionals to check the return value.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If the return value is X, then print out that the winner is player 1, whereas if the return value is O, then the winner is player 2.<\/p>\n\n\n\n<div id=\"cstm_banner_cta\"><\/div>\n\n\n\n<ol start=\"10\" class=\"wp-block-list\">\n<li><strong>Check Whether It\u2019s Ended in a Tie<\/strong><\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">The game ends in a tie if the game board is already filled but there is no winner (no character lines up in a row, column, or diagonal).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The existence of any vacant spaces on the game board can be checked using a function that we can create. Vacant spaces are denoted by a dash (-). If the game board is full, this function will return true; otherwise, it will return false.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>Hint: <\/em><\/strong><em>use nested for loops to iterate through each row and column. Use <strong>if<\/strong> conditional to check whether <strong>gameBoard[i][j]<\/strong> is equal to <strong>\u2018-\u2018<\/strong>. If it is so, then return false.<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Conclusion<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Tic Tac Toe game is a classic programming problem that is actually quite simple to build. By creating this project you are implementing as well as learning about arrays, data structure, Booleans, variables, conditionals checking, and many more.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Don\u2019t ever be satisfied with only one project, keep improving your coding skills by creating another game and solving other programming problems.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To get your hands on more educational and free resources on\u00a0<a href=\"\/\/brightchamps.com\/blog\/kids-coding-languages\/\" target=\"_blank\" rel=\"noreferrer noopener\">coding for kids<\/a>, financial education for kids, and\u00a0<a href=\"https:\/\/brightchamps.com\/blog\/ultimate-guide-to-robotics-for-kids\/\">robotics for kids<\/a>\u00a0do check out the\u00a0<a href=\"https:\/\/brightchamps.com\/\">BrightCHAMPS<\/a>\u00a0Page now!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Last but not least if you want to learn coding and creating your own game, you can Sign up for BrightCHAMPS trial class and you will see something interesting more than you bargain for.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Almost all of us are familiar with the tic tac toe game. This strategy game is quite easy to play but kind of challenging to beat the opponent.&nbsp; Back then we can play this game simply with a piece of paper and pen. Draw a 3&#215;3 grid and start to write down O or X [&hellip;]<\/p>\n","protected":false},"author":10,"featured_media":11940,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"off","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[24],"tags":[68],"class_list":["post-11939","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-parenting","tag-codechamps"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to create a Tic Tac Toe Game in Java - BrightChamps Blog<\/title>\n<meta name=\"description\" content=\"Discover the ultimate guide to creating a Tic Tac Toe game in Java! Dive into step-by-step tutorials to master the art of game development.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/brightchamps.com\/blog\/tic-tac-toe-game-in-java\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to create a Tic Tac Toe Game in Java - BrightChamps Blog\" \/>\n<meta property=\"og:description\" content=\"Discover the ultimate guide to creating a Tic Tac Toe game in Java! Dive into step-by-step tutorials to master the art of game development.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/brightchamps.com\/blog\/tic-tac-toe-game-in-java\/\" \/>\n<meta property=\"og:site_name\" content=\"BrightChamps Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/BrightChamps-101266664954230\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-31T08:44:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-10-01T10:46:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/brightchamps.com\/blog\/wp-content\/uploads\/2022\/10\/Tic-Tac-Toe-Game-in-Java.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"800\" \/>\n\t<meta property=\"og:image:height\" content=\"451\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Nurinnajiah Tsani\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nurinnajiah Tsani\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/brightchamps.com\\\/blog\\\/tic-tac-toe-game-in-java\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/brightchamps.com\\\/blog\\\/tic-tac-toe-game-in-java\\\/\"},\"author\":{\"name\":\"Nurinnajiah Tsani\",\"@id\":\"https:\\\/\\\/brightchamps.com\\\/blog\\\/#\\\/schema\\\/person\\\/c90663d645c43c11c7ea04cb1f2c9092\"},\"headline\":\"How to create a Tic Tac Toe Game in Java\",\"datePublished\":\"2022-10-31T08:44:45+00:00\",\"dateModified\":\"2024-10-01T10:46:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/brightchamps.com\\\/blog\\\/tic-tac-toe-game-in-java\\\/\"},\"wordCount\":1378,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/brightchamps.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/brightchamps.com\\\/blog\\\/tic-tac-toe-game-in-java\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/brightchamps.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/10\\\/Tic-Tac-Toe-Game-in-Java.jpg\",\"keywords\":[\"CodeChamps\"],\"articleSection\":[\"Parenting Tips\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/brightchamps.com\\\/blog\\\/tic-tac-toe-game-in-java\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/brightchamps.com\\\/blog\\\/tic-tac-toe-game-in-java\\\/\",\"url\":\"https:\\\/\\\/brightchamps.com\\\/blog\\\/tic-tac-toe-game-in-java\\\/\",\"name\":\"How to create a Tic Tac Toe Game in Java - BrightChamps Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/brightchamps.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/brightchamps.com\\\/blog\\\/tic-tac-toe-game-in-java\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/brightchamps.com\\\/blog\\\/tic-tac-toe-game-in-java\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/brightchamps.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/10\\\/Tic-Tac-Toe-Game-in-Java.jpg\",\"datePublished\":\"2022-10-31T08:44:45+00:00\",\"dateModified\":\"2024-10-01T10:46:33+00:00\",\"description\":\"Discover the ultimate guide to creating a Tic Tac Toe game in Java! Dive into step-by-step tutorials to master the art of game development.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/brightchamps.com\\\/blog\\\/tic-tac-toe-game-in-java\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/brightchamps.com\\\/blog\\\/tic-tac-toe-game-in-java\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/brightchamps.com\\\/blog\\\/tic-tac-toe-game-in-java\\\/#primaryimage\",\"url\":\"https:\\\/\\\/brightchamps.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/10\\\/Tic-Tac-Toe-Game-in-Java.jpg\",\"contentUrl\":\"https:\\\/\\\/brightchamps.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/10\\\/Tic-Tac-Toe-Game-in-Java.jpg\",\"width\":800,\"height\":451,\"caption\":\"Tic Tac Toe Game in Java\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/brightchamps.com\\\/blog\\\/tic-tac-toe-game-in-java\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/brightchamps.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Parenting Tips\",\"item\":\"https:\\\/\\\/brightchamps.com\\\/blog\\\/parenting\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"How to create a Tic Tac Toe Game in Java\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/brightchamps.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/brightchamps.com\\\/blog\\\/\",\"name\":\"BrightChamps Blog\",\"description\":\"BrightChamps Blog, also known as BrightChamps Hub is a go-to resource hub for everything on Coding for kids\",\"publisher\":{\"@id\":\"https:\\\/\\\/brightchamps.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/brightchamps.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/brightchamps.com\\\/blog\\\/#organization\",\"name\":\"BrightChamps\",\"url\":\"https:\\\/\\\/brightchamps.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/brightchamps.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/brightchamps.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/03\\\/BrightCHAMPS-logo-new-1.png\",\"contentUrl\":\"https:\\\/\\\/brightchamps.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/03\\\/BrightCHAMPS-logo-new-1.png\",\"width\":417,\"height\":80,\"caption\":\"BrightChamps\"},\"image\":{\"@id\":\"https:\\\/\\\/brightchamps.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/BrightChamps-101266664954230\\\/\",\"https:\\\/\\\/www.instagram.com\\\/brightchamps\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/brightchamps\\\/mycompany\\\/\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UC_Afe_rMGoK5Bs4nSt8QIzQ\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/brightchamps.com\\\/blog\\\/#\\\/schema\\\/person\\\/c90663d645c43c11c7ea04cb1f2c9092\",\"name\":\"Nurinnajiah Tsani\",\"description\":\"\u2b50\u2b50\u2b50\u2b50\u2b50 I am a nature enthusiast and IT expert who enjoys teaching and learning with children and volunteering with humanitarian organizations. At BrightChamps, my goal is to make the kids future-ready by strengthening their IT skills. Learn from Me\",\"url\":\"https:\\\/\\\/brightchamps.com\\\/blog\\\/author\\\/nurinnajiahtsani\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to create a Tic Tac Toe Game in Java - BrightChamps Blog","description":"Discover the ultimate guide to creating a Tic Tac Toe game in Java! Dive into step-by-step tutorials to master the art of game development.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/brightchamps.com\/blog\/tic-tac-toe-game-in-java\/","og_locale":"en_US","og_type":"article","og_title":"How to create a Tic Tac Toe Game in Java - BrightChamps Blog","og_description":"Discover the ultimate guide to creating a Tic Tac Toe game in Java! Dive into step-by-step tutorials to master the art of game development.","og_url":"https:\/\/brightchamps.com\/blog\/tic-tac-toe-game-in-java\/","og_site_name":"BrightChamps Blog","article_publisher":"https:\/\/www.facebook.com\/BrightChamps-101266664954230\/","article_published_time":"2022-10-31T08:44:45+00:00","article_modified_time":"2024-10-01T10:46:33+00:00","og_image":[{"width":800,"height":451,"url":"https:\/\/brightchamps.com\/blog\/wp-content\/uploads\/2022\/10\/Tic-Tac-Toe-Game-in-Java.jpg","type":"image\/jpeg"}],"author":"Nurinnajiah Tsani","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Nurinnajiah Tsani","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/brightchamps.com\/blog\/tic-tac-toe-game-in-java\/#article","isPartOf":{"@id":"https:\/\/brightchamps.com\/blog\/tic-tac-toe-game-in-java\/"},"author":{"name":"Nurinnajiah Tsani","@id":"https:\/\/brightchamps.com\/blog\/#\/schema\/person\/c90663d645c43c11c7ea04cb1f2c9092"},"headline":"How to create a Tic Tac Toe Game in Java","datePublished":"2022-10-31T08:44:45+00:00","dateModified":"2024-10-01T10:46:33+00:00","mainEntityOfPage":{"@id":"https:\/\/brightchamps.com\/blog\/tic-tac-toe-game-in-java\/"},"wordCount":1378,"commentCount":0,"publisher":{"@id":"https:\/\/brightchamps.com\/blog\/#organization"},"image":{"@id":"https:\/\/brightchamps.com\/blog\/tic-tac-toe-game-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/brightchamps.com\/blog\/wp-content\/uploads\/2022\/10\/Tic-Tac-Toe-Game-in-Java.jpg","keywords":["CodeChamps"],"articleSection":["Parenting Tips"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/brightchamps.com\/blog\/tic-tac-toe-game-in-java\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/brightchamps.com\/blog\/tic-tac-toe-game-in-java\/","url":"https:\/\/brightchamps.com\/blog\/tic-tac-toe-game-in-java\/","name":"How to create a Tic Tac Toe Game in Java - BrightChamps Blog","isPartOf":{"@id":"https:\/\/brightchamps.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/brightchamps.com\/blog\/tic-tac-toe-game-in-java\/#primaryimage"},"image":{"@id":"https:\/\/brightchamps.com\/blog\/tic-tac-toe-game-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/brightchamps.com\/blog\/wp-content\/uploads\/2022\/10\/Tic-Tac-Toe-Game-in-Java.jpg","datePublished":"2022-10-31T08:44:45+00:00","dateModified":"2024-10-01T10:46:33+00:00","description":"Discover the ultimate guide to creating a Tic Tac Toe game in Java! Dive into step-by-step tutorials to master the art of game development.","breadcrumb":{"@id":"https:\/\/brightchamps.com\/blog\/tic-tac-toe-game-in-java\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/brightchamps.com\/blog\/tic-tac-toe-game-in-java\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/brightchamps.com\/blog\/tic-tac-toe-game-in-java\/#primaryimage","url":"https:\/\/brightchamps.com\/blog\/wp-content\/uploads\/2022\/10\/Tic-Tac-Toe-Game-in-Java.jpg","contentUrl":"https:\/\/brightchamps.com\/blog\/wp-content\/uploads\/2022\/10\/Tic-Tac-Toe-Game-in-Java.jpg","width":800,"height":451,"caption":"Tic Tac Toe Game in Java"},{"@type":"BreadcrumbList","@id":"https:\/\/brightchamps.com\/blog\/tic-tac-toe-game-in-java\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/brightchamps.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Parenting Tips","item":"https:\/\/brightchamps.com\/blog\/parenting\/"},{"@type":"ListItem","position":3,"name":"How to create a Tic Tac Toe Game in Java"}]},{"@type":"WebSite","@id":"https:\/\/brightchamps.com\/blog\/#website","url":"https:\/\/brightchamps.com\/blog\/","name":"BrightChamps Blog","description":"BrightChamps Blog, also known as BrightChamps Hub is a go-to resource hub for everything on Coding for kids","publisher":{"@id":"https:\/\/brightchamps.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/brightchamps.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/brightchamps.com\/blog\/#organization","name":"BrightChamps","url":"https:\/\/brightchamps.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/brightchamps.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/brightchamps.com\/blog\/wp-content\/uploads\/2026\/03\/BrightCHAMPS-logo-new-1.png","contentUrl":"https:\/\/brightchamps.com\/blog\/wp-content\/uploads\/2026\/03\/BrightCHAMPS-logo-new-1.png","width":417,"height":80,"caption":"BrightChamps"},"image":{"@id":"https:\/\/brightchamps.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/BrightChamps-101266664954230\/","https:\/\/www.instagram.com\/brightchamps\/","https:\/\/www.linkedin.com\/company\/brightchamps\/mycompany\/","https:\/\/www.youtube.com\/channel\/UC_Afe_rMGoK5Bs4nSt8QIzQ"]},{"@type":"Person","@id":"https:\/\/brightchamps.com\/blog\/#\/schema\/person\/c90663d645c43c11c7ea04cb1f2c9092","name":"Nurinnajiah Tsani","description":"\u2b50\u2b50\u2b50\u2b50\u2b50 I am a nature enthusiast and IT expert who enjoys teaching and learning with children and volunteering with humanitarian organizations. At BrightChamps, my goal is to make the kids future-ready by strengthening their IT skills. Learn from Me","url":"https:\/\/brightchamps.com\/blog\/author\/nurinnajiahtsani\/"}]}},"_links":{"self":[{"href":"https:\/\/brightchamps.com\/blog\/wp-json\/wp\/v2\/posts\/11939","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/brightchamps.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/brightchamps.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/brightchamps.com\/blog\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/brightchamps.com\/blog\/wp-json\/wp\/v2\/comments?post=11939"}],"version-history":[{"count":5,"href":"https:\/\/brightchamps.com\/blog\/wp-json\/wp\/v2\/posts\/11939\/revisions"}],"predecessor-version":[{"id":32395,"href":"https:\/\/brightchamps.com\/blog\/wp-json\/wp\/v2\/posts\/11939\/revisions\/32395"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/brightchamps.com\/blog\/wp-json\/wp\/v2\/media\/11940"}],"wp:attachment":[{"href":"https:\/\/brightchamps.com\/blog\/wp-json\/wp\/v2\/media?parent=11939"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/brightchamps.com\/blog\/wp-json\/wp\/v2\/categories?post=11939"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/brightchamps.com\/blog\/wp-json\/wp\/v2\/tags?post=11939"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}