Sunday, January 29, 2017

Lottery Draw Java

Tags

Following program will produce a ticket number with given no of digits randomly and will help in Lottery Draw :

Code::

import java.util.*;
public class LotteryDraw 
{
    public static void main(String[] nt) 
    {
        Scanner in=new Scanner(System.in);
        System.out.print("How many digits a ticket have: ");
        int k=in.nextInt();
        int [] num=new int[10];
        for(int i=0;i<num.length;i++)
        {
            num[i]=i;
        }
        int [] result=new int[k];
        for(int i=0;i<result.length;i++)
        {
            int r=(int)(Math.random()*10); //here 10 bcz the random function will produce positive value less than 1.0 
            result[i]=num[r];
        }
        System.out.print("So the Jackpot Ticket is: ");
        for(int i=0;i<result.length;i++)
        {
            System.out.print(result[i]);
        }
        System.out.println();
    }
}

Output::