Go to Top

Wednesday, 28 September 2011

Utilities 6 - Playing housie

So, you have no one to pick up the lot numbers, or do all of your friends want to play ? Java to the rescue again. This java program will help you to pick random numbers from the lot.

Java Program : 

import java.io.*;
import java.util.*;
class housie
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    static int n1,n2;
    static int[] a;
    static Random r=new Random();
    static void main()throws IOException
    {
         input();
         iterate();
    }
    static void input()throws IOException
    {
        int c1=0,i;
        System.out.print("Enter the lower limit of lot numbers : ");
        n1=Integer.parseInt(br.readLine());
        System.out.print("\nEnter the upper limit of lot numbers : ");
        n2=Integer.parseInt(br.readLine());
        a=new int[(n2-n1)+1];
        for(i=n1;i<=n2;i++)
        {
            a[c1]=i;
            c1++;
        }
    }
    static void iterate()throws IOException
    {
        int i,c,l=a.length;
        String s;
        for(i=0;i<l;i++)
        {
            c=r.nextInt(a.length);
            if(a[c]<0)
            l++;
            else
            {
                System.out.print("\nLucky number is : "+a[c]);
                s=br.readLine();
                a[c]=-1;
            }
        }
    }
}

Again, just put in the upper and lower limit of the lots numbers and press return. CLICK HERE to know hoe to generate random housie tickets.

1 comment:

  1. i just need the output of this n in which version we can run this code??

    ReplyDelete

ShareThis