Make a coin toss program in java

                                      Coin toss program

 You can easily create a coin toss program in java using a random number generator. If you complete your project then please send the project in riteshregmi85@gmail.com.

note: The program you see bellow is created by The owner of this website. If you don't have a permission to use this program then don't use this program. Because This source code is copyrighted under the act of 107.


package com.ritesh;

import java.util.Random;
import java.util.Scanner;

public class toss {
public static void main(String[] args) {
coin();

}
public static void coin()
{
System.out.println(" ");
System.out.println("Enter Your toss Head and Tail\n");
System.out.print("For head Enter 'Head' or 'H' or '1' \t");
System.out.println("For Tail Enter 'Tailed' or 'T' or '2'");
Scanner sc=new Scanner(System.in);
String st=sc.nextLine().toLowerCase();
int num;
if(st.equals("head")||st.equals("H")||st.equals("1"))
{
System.out.println("You chose head");
System.out.println("Your enemy chose tail");
num=1;
}
else if(st.equals("tail")||st.equals("t")||st.equals("2"))
{
System.out.println("You chose tail");
System.out.println("Your enemy chose head");
num=2;
}


Random number=new Random();
int rand;
rand=number.nextInt(3-1)+1;

switch (rand)
{
case 1->{
System.out.println(" ");
System.out.println("Head come up");
System.out.println("Head won");
}
case 2->{
System.out.println(" ");

System.out.println("Tail come up");
System.out.println("Tail won");
}
}



}
}

CodePen - Coin Flip

Click on coin to flip

Comments