Thursday, November 18, 2010

program to display lucky number in java

import java.io.*;
class lucky
    {
        public static void meth()throws IOException
        {
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
   
    System.out.println("enter limit");
    int n=Integer.parseInt(br.readLine());
   int ar[]=new int[n];
   for(int i=0;i<n;i++)
    ar[i]=i+1;
      
       int a,b,c,d;
        a=1;
      
        b=ar.length;
        int gap=2;
        while(true)
        {
        for(c=a;c<b;c=c+gap)
            {
                ar[c]=-1;
            }
        d=0;
        for(c=0;c<b;c++)
            {
                if(ar[c] != -1)
                    d++;
            }
        int temp[]=new int[d];
        int p=0;
        for(c=0;c<b;c++)
            {
                if(ar[c] != -1)
                    temp[p++]=ar[c];
                ar[c]=-1;
            }
         for(c=0;c<p;c++)
            {
                ar[c]=temp[c];
            }
         a=a+1;
         gap++;
         if(a>d)
            {
                break;
            }
        }
      int res=0;
      for(int i=0;i<8;i++)
        {
            if(ar[i] != -1)
                {
                    int digi=ar[i];
                    c=0;
                    while(digi>0)
                        {
                            c++;
                            digi/=10;
                        }
                    double t=Math.pow(10,c);
                    res=(res*(int)t)+ar[i];
                }
            }
         System.out.println(res);
       }
    }

14 comments:

Saikat said...

gr8.Runs perfectly...!!!

yuukizerofy said...

xplain....

Anonymous said...

thnx.. runs fine

Anonymous said...

runs perfectly very nice....

Anonymous said...

are date important for boards

Anonymous said...

It is wrong! Check out the Wikipedia page for the same or the wolfram page for the same topic. U got the definition of the sets wrong!

Vamsi Sai said...

yes!! this program is wrong!
check this:
http://www.codedb.tk/code/E25zrRo

naved ahmad said...
This comment has been removed by the author.
naved ahmad said...
This comment has been removed by the author.
naved ahmad said...
This comment has been removed by the author.
naved ahmad said...

guys check this out....
import java.io.*;
public class lucky_n
{
int c;
public int[] deduce(int a[],int n)
{
int s=0,x;
int len=a.length;
int b[]=new int[len];
int i=0,index=0;
for(i=0;i1)
{
if(d==3)
{
d=d+1;
}
c=deduce(a,d);
d=d+1;
e=deduce(c,d);
a=e;
if(c.length==e.length)
{
b=0;
}
}
for(int i=0;i<c.length;i++)
System.out.print(c[i]+" ");
}
}

RohanSingh said...
This comment has been removed by the author.
RohanSingh said...

import java.io.*;
class LuckyNumber
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the Number of Elements : ");
int n=Integer.parseInt(br.readLine());
int a[]=new int[n];
int c=n;
for(int i=0;i<n;i++)
{
a[i]=i+1;
}
int del=1;
while(del<n)
{
for(int i=del;i<n;i+=del)
{
for(int j=i;j<n-1;j++)
{
a[j]=a[j+1];
}
n--;
}
del++;
}
System.out.print("The Lucky Numbers of "+c+" are : ");
for(int i=0;i<n;i++)
{
System.out.print(a[i]+" ");
}
System.out.println();
}
}

Anonymous said...

/** A Program to print the Lucky Numbers upto a given limit */

import java.io.*;
public class Lucky_Numbers
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the Limit(N) : ");
int n=Integer.parseInt(br.readLine());
int a[]=new int[n];
int c=n;
for(int i=0;i<n;i++)
{
a[i]=i+1;
}
int d=1;
while(d<n)
{
for(int i=d; i<n; i+=d)
{
for(int j=i; j<n-1; j++)
{
a[j]=a[j+1];
}
n--;
}
d++;
}
System.out.print("The Lucky Numbers Less than "+c+" are : ");
for(int i=0; i<n; i++)
{
System.out.print(a[i]+" ");
}
}
}