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)         {             System.out.println("Blackjack! Player Wins!");    return;         } System.out.println();                  int dealer_random1 = 100;         int dealer_random2 = 100;                  while(dealer_random1 >= 12 || deale

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];                  //3 arrays declared         char missed[] = new char[randomWord.length()];//to record missed letters         char guessed[] = new char[randomWord.length()];//to record the currently guessed word         char correct[] = new char[randomWord.length()];//to record the correct l

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 user will get an additional chance         if(input(main, 'O')){             return;         }         System.out.println("The game is tie!");     }          //----------taking the input from 2 users     public static boolean input(char arr[][],char c){         Scanner input = new Scanner(System.in);         int row,column;                  System.out.print("'"+c+"' choose your location(row,column)