This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tictactoe; | |
import java.util.Scanner; | |
public class TikTakToeGame { | |
private final char[][] state = { | |
{'_', '_', '_'}, | |
{'_', '_', '_'}, | |
{'_', '_', '_'} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tictactoe; | |
public enum Messages { | |
ASK_COORDINATES("Enter the coordinates: "), | |
ERROR_ONLY_NUMBERS("You should enter numbers!"), | |
ERROR_INCORRECT_RANGE("Coordinates should be from 1 to 3!"), | |
ERROR_OCCUPIED_CELL("This cell is occupied! Choose another one!"), | |
NOT_FINISHED("Game not finished"), | |
DRAW("Draw"), | |
WINNER_X("X wins"), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tictactoe; | |
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(System.in); | |
TikTakToeGame game = new TikTakToeGame(); | |
System.out.println(game.getState()); | |
System.out.print(Messages.ASK_COORDINATES.message); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tictactoe; | |
import java.util.Scanner; | |
public class TikTakToeGame { | |
private char[][] state; | |
private int column; | |
private int row; | |
public TikTakToeGame(char[][] initialState) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tictactoe; | |
public enum Messages { | |
ASK("Enter cells: "), | |
ASK_COORDINATES("Enter the coordinates: "), | |
ERROR_ONLY_NUMBERS("You should enter numbers!"), | |
ERROR_INCORRECT_RANGE("Coordinates should be from 1 to 3!"), | |
ERROR_OCCUPIED_CELL("This cell is occupied! Choose another one!"), | |
NOT_FINISHED("Game not finished"), | |
DRAW("Draw"), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tictactoe; | |
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(System.in).useDelimiter(""); | |
char[][] state = new char[3][3]; | |
int i = 0; | |
int j = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
class Main { | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(System.in); | |
int sum = 0; | |
int num; | |
boolean barrier = false; | |
while (!barrier) { | |
num = scanner.nextInt(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
class Main { | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(System.in); | |
int externalSize = scanner.nextInt(); | |
int internalSize = scanner.nextInt(); | |
int[][] matrix = new int[externalSize][internalSize]; | |
for (int i = 0; i < matrix.length; i++) { | |
for (int j = 0; j < matrix[i].length; j++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
class Main { | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(System.in); | |
int max = 0; | |
while (scanner.hasNextInt()) { | |
int input = scanner.nextInt(); | |
if (input % 4 == 0 && input > max) { | |
max = input; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
class Main { | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(System.in); | |
int shape = scanner.nextInt(); | |
String message; | |
switch (shape) { | |
case 1: | |
message = "You have chosen a square"; |