Back to Top
  • We are Certified Personal Trainer’s

  • Do Work That Aligns with your Heart

  • A Fresh Approach To Health & Life


Tic Tac Toe

Tic Tac Toe

Certainly! Here's a simple implementation of the Tic Tac Toe game in Java: ```java import java.util.Scanner; public class TicTacToe { private char[][] board; private char currentPlayer; private boolean gameWon; public TicTacToe() { board = new char[3][3]; currentPlayer = 'X'; gameWon = false; initializeBoard(); } public void initializeBoard() { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { board[i][j] = '-'; } } } public void printBoard() { System.out.println("-------------"); for (int i = 0; i < 3; i++) { System.out.print("| "); for (int j = 0; j < 3; j++) { System.out.print(board[i][j] + " | "); } System.out.println(); System.out.println("-------------"); } } public void playGame() { Scanner scanner = new Scanner(System.in); while (!gameWon) { System.out.println("Player " + currentPlayer + "'s turn."); System.out.print("Enter row (0-2): "); int row = scanner.nextInt(); System.out.print("Enter column (0-2): "); int col = scanner.nextInt(); if (isValidMove(row, col)) { board[row][col] = currentPlayer; printBoard(); if (checkWin(row, col)) { System.out.println("Player " + currentPlayer + " wins!"); gameWon = true; } else if (isBoardFull()) { System.out.println("It's a tie!"); gameWon = true; } else { currentPlayer = (currentPlayer == 'X') ? 'O' : 'X'; } } else { System.out.println("Invalid move! Please try again."); } } scanner.close(); } public boolean isValidMove(int row, int col) { if (row < 0 || row >= 3 || col < 0 || col >= 3) { return false; } return board[row][col] == '-'; } public boolean checkWin(int row, int col) { // Check row if (board[row][0] == board[row][1] && board[row][1] == board[row][2]) { return true; } // Check column if (board[0][col] == board[1][col] && board[1][col] == board[2][col]) { return true; } // Check diagonals if (board[0][0] == board[1][1] && board[1][1] == board[2][2] && board[1][1] != '-') { return true; } if (board[0][2] == board[1][1] && board[1][1] == board[2][0] && board[1][1] != '-') { return true; } return false; } public boolean isBoardFull() { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (board[i][j] == '-') { return false; } } } return true; } public static void main(String[] args) { TicTacToe game = new TicTacToe(); game.playGame(); } } ``` To play the game, simply run the `main` method. Players will take turns entering the row and column numbers to place their mark ('X' or 'O') on the board. The game will continue until a player wins or the board is full, resulting in a tie.

Jffb

 

AI Content Detection

 

IFSC Code Lookup

IFSC Code Lookup





BasicFitnessGuides: Your Ultimate Resource for Achieving Fitness Goals

 BasicFitnessGuides: Your Ultimate Resource for Achieving Fitness Goals


Welcome to BasicFitnessGuides, your comprehensive source of information and guidance on all things fitness. Whether you're a beginner taking your first steps towards a healthier lifestyle or a fitness enthusiast looking to elevate your training, our website is designed to empower and support you on your fitness journey. With expert advice, practical tips, and a community of like-minded individuals, BasicFitnessGuides is here to help you achieve your fitness goals.


Discover a Wealth of Fitness Knowledge:


At BasicFitnessGuides, we believe that knowledge is the foundation of success. Our website is packed with informative articles, in-depth guides, and expert insights to provide you with the knowledge you need to make informed decisions about your fitness routine. From understanding different exercise techniques to learning about the science of nutrition, our content covers a wide range of topics to help you build a solid fitness foundation.


Get Expert Guidance:

Our team of experienced fitness professionals and wellness experts is dedicated to providing you with reliable and evidence-based information. Whether you're looking for workout routines, dietary advice, or tips on injury prevention, our experts are here to guide you every step of the way. We stay up-to-date with the latest research and industry trends, ensuring that you receive the most accurate and effective guidance for your fitness goals.


Practical Tips for Real Results:

We understand that implementing changes and maintaining consistency can be challenging. That's why we focus on providing practical tips and actionable advice that you can easily incorporate into your daily life. Our aim is to help you overcome obstacles, stay motivated, and achieve real results. From time-saving workout tips to healthy recipe ideas, we're here to make your fitness journey enjoyable and sustainable.

Join a Supportive Community:

At BasicFitnessGuides, we believe that fitness is not just an individual pursuit—it's a journey best shared with others. Our website fosters a supportive community where you can connect with fellow fitness enthusiasts, share your experiences, ask questions, and find inspiration. Surrounding yourself with like-minded individuals can boost motivation, provide accountability, and make your fitness journey more enjoyable.


Stay Updated and Engaged:

As a member of the BasicFitnessGuides community, you'll have access to regular updates, fresh content, and exciting opportunities. We'll keep you informed about the latest fitness trends, provide tips for overcoming plateaus, and share success stories from individuals who have transformed their lives through fitness. Engage with our content, leave comments, and let us know what topics you'd like us to cover. We're here to tailor our content to meet your needs and interests.


Conclusion:


BasicFitnessGuides is your one-stop destination for all your fitness needs. Whether you're looking for guidance on workout routines, nutrition advice, or support from a community of passionate individuals, we've got you covered. Start exploring our website today, and let BasicFitnessGuides be your trusted companion on your journey to a healthier, fitter, and more fulfilling life. Together, we'll make your fitness goals a reality!


Remember, it's never too late to start prioritizing your health and well-being. Take that first step with BasicFitnessGuides and unlock your potential for a happier and healthier future.


Welcome to the BasicFitnessGuides community, where fitness meets empowerment!