Skip to main content

Posts

Showing posts from February, 2016

SIMPLE BLACKJACK GAME IN JAVA (CONSOLE)

import java.util.Scanner; class BlackJack{     public static void main(String[] args)      {         int player_random1 = 100;         int player_random2 = 100;         while(player_random1 >= 12 || player_random2 >= 12  || player_random1 < 3 || player_random2 <3)         {             player_random1 = (int)(Math.random()*100);             player_random2 = (int)(Math.random()*100);         }                  int player_total = player_random1 + player_random2;                  System.out.println("You get a "+player_random1+" and a "+player_random2);         System.out.println("Your total is "+player_total); if(player_total==21)  ...

HANGMAN USING JAVA (CONSOLE)

SOURCE CODE import java.util.Scanner; class Hangman {     public static void main(String[] args) {         String words_list = "cheese puppies hello tree mango pineapple flowers basket lamp ceiling";         String[] wordsAsArray = words_list.split(" ");         int index;                  //to pick a random integer which is less than the number of array elements and greater than or equal to 0         do{             index =(int) (Math.random() * 10);         }         while(index<0 || index>=wordsAsArray.length);                  //To pick the word that corresponds to the random index picked         String randomWord = wordsAsArray[index];             ...

TIC TAC TOE GAME IN JAVA (CONSOLE)

SOURCE CODE import java.util.Scanner; class TicTacToe {     public static void main(String[] args) {         char[][] main = new char[3][3];                  for(int i=0; i<3; i++){             for(int j=0; j<3; j++){                 main[i][j]=' ';             }         }                  for(int i=0; i<4; i++){             if(input(main, 'O')){                 return;             }             if(input(main, 'X')){                 return;             }         }         //1st...