Program to calculate Lottery Odds of a Lottery Draw :
import java.util.*;
public class Lottery
{
public static void main(String[] nt)
{
Scanner in=new Scanner(System.in);
System.out.println("Enter Total Numbers");
int a=in.nextInt();
System.out.println("Enter Total Numbers to draw");
int b=in.nextInt();
double lottery=1;
for(int i=1;i<=b;i++)
{
lottery=lottery*(a-i+1)/i; //combination
}
System.out.println("Total Lottery odds are "+lottery);
}
}
Output:
Lottery Odds : In a typical 6/49 game, each player chooses six non-duplicate numbers from a range of 1-49. If the six numbers on a ticket match the numbers drawn by the lottery, the ticket holder is a jackpot winner—regardless of the order of the numbers. The probability of this happening is 1 in 13,983,816.
Following is the code to find lottery odds:
public class Lottery
{
public static void main(String[] nt)
{
Scanner in=new Scanner(System.in);
System.out.println("Enter Total Numbers");
int a=in.nextInt();
System.out.println("Enter Total Numbers to draw");
int b=in.nextInt();
double lottery=1;
for(int i=1;i<=b;i++)
{
lottery=lottery*(a-i+1)/i; //combination
}
System.out.println("Total Lottery odds are "+lottery);
}
}
Output: