This is a small program that shows how to create a TicTacToe game in Java.
The purpose of the game is to get three in a row before your opponent does, either vertically, horizontally or diagonally.
The TicTacToe program is made up of two Java classes. One is called TicTacToe and that is the actual game class that contains much of the logic for the game.
The other class called Main is the class that starts the game, displays the rules and loops for as many times as there are moves by the users.
The Main class looks like this:
This example shows how to take input from the user and convert pound to Kilogram and also how to convert Ounce to Kilogram.
The user should first enter a number in pound. The program makes the conversion to Kilogram and prints out the result.
Next the user is asked to enter a number in ounce. The program makes the conversion to Kilogram and prints out the result.
It uses a BufferedReader and InputStreamReader to collect the input from the user.
The purpose of the HiLo (or Hi-Lo) game is to guess the right number in a certain number of attempts. If the guess is too high the word HI is printed out and if the guess is too low the word LO is printed out.
In this example you have six attempts to guess the right number. The code consists of two classes, one main class and one class that contains the actual game logic.
The HiLo class generates its secret number, between 1-100, with the java.util.Random class.