Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

[HELP] Head or Tails game

$
0
0
Hey guys, I wrote a working code of this "head or tails" game but I want to change it a little but not sure how. This is my code:
import java.util.Scanner;
 public class HeadOrTail{
  public static void main(String[] args){
  
   //Generate the number 1 and 0 to specify head or tails
   int number=(int)(Math.random()*2);
   
   //Create a Scanner
   Scanner input=new Scanner(System.in);
   
   //Prompt user to guess
   System.out.print("Guess head or tail of a coin, Enter 0 for head or 1 for tail: ");
   int guess=input.nextInt();
      
   //Specifing head or tails
   if (number==guess)  
    System.out.println("You are correct!");
   else if (number==1)
    System.out.println("You are incorrect, it is tail.");   
   else 
    System.out.println("You are incorrect, it is head.");
	
 }
}

I want to change it so that instead of entering 1 and 0, the user type in "head" or "tail". Is it possible? Explain please...:P

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>