Java Project – Coin Toss Game

Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java

Program 1

// Con Toss Game 
import java.util.Scanner;
import java.util.Random;
    
public class CoinTossGame 
{
  public static void main(String[] args) 
  {
    String choice;
    do
    {
         Scanner scan=new Scanner(System.in);
         Random random=new Random();
         int coinchoice,userchoice;
         coinchoice=random.nextInt(2);
         //System.out.println(coinchoice);
         System.out.println("-----------Coin Toss Game----------------");
         System.out.println("1.Head \n2.Tail");         
         System.out.println("--------------------------------------------");
         System.out.println("Enter your choice(1 for Head 2 for Tail): ");
        userchoice=scan.nextInt();
        if(coinchoice==1)
        System.out.println("Its a Head.....");
        else
        System.out.println("Its a Tail.....");
        if(coinchoice==userchoice)
        System.out.println("You won the toss...!");
        else
        System.out.println("Opps you lose the toss... !");
        System.out.println("Do you want to play more...!(yes/no)");    
        choice=scan.next().toLowerCase();
    }while(choice.equals("yes"));
    System.out.println("Thanks for playing .. Bye Bye");
  }    
}

 

 

You give me 15 seconds I promise you best tutorials
Please share your happy experience on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *