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

Comments

Popular posts from this blog

Sort Boundary Elements Of A Matrix

Program to fill a square matrix of size ‘n*n” in a circular fashion (clockwise) with natural numbers from 1 to n*n, taking ‘n’ as input.