Lucky Number In Java ISC
Write a program to generate and print lucky numbers less than a given number N.
import java.util.*;
class LuckyNumbers
{//start of class
public void accept(int n)
{
int a[]=new int[n];
int c=n;
for(int i=0;i<n;i++){
a[i]=i+1;
}
int del=1;
System.out.println("Lucky Number Operation :n");
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++;
for(int i=0;i<n;i++){
System.out.print(a[i]+"");
}
System.out.println();
}
//end of while
System.out.print("Hence, the Lucky Numbers Less than equal to " + c + " are : ");
for(int i=0; i<n; i++)
{
System.out.print(a[i]+" ");
}
}}//end of class
OTPUT---
Hence, the Lucky Numbers Less than equal to 24 are : 1 3 7 13 19
import java.util.*;
class LuckyNumbers
{//start of class
public void accept(int n)
{
int a[]=new int[n];
int c=n;
for(int i=0;i<n;i++){
a[i]=i+1;
}
int del=1;
System.out.println("Lucky Number Operation :n");
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++;
for(int i=0;i<n;i++){
System.out.print(a[i]+"");
}
System.out.println();
}
//end of while
System.out.print("Hence, the Lucky Numbers Less than equal to " + c + " are : ");
for(int i=0; i<n; i++)
{
System.out.print(a[i]+" ");
}
}}//end of class
OTPUT---
Hence, the Lucky Numbers Less than equal to 24 are : 1 3 7 13 19
Comments
Post a Comment