my code prints lucky numbers,
1, 3, 7, 9, 13, 15, 21, 25, 31, 33, 37, 43, 49, 51, 63, 67, 69, 73, 75, 79, 87, 93, 99 etc
http://en.wikipedia.org/wiki/Lucky_number
but i don't like the eliminate method. instead of a boolean array,would using an arraylist be better, so i could remove the appropriate numbers?
class LuckyNumbers {
static boolean bls[];
public static void main(String[] args) {
for(int n = 1; n <= 300; n++) {
if(isALuckyNumber(n)) System.out.print(n+" ");
}
}
static boolean isALuckyNumber(int n) {
bls = new boolean[n+1];
for(int i = 2; i < bls.length; i++) {
if(bls[i] == false) eliminate(i);
}
if(bls[n] == false) return true;
else return false;
}
static void eliminate(int n) {
int count = 0;
for(int i = 1; i < bls.length; i++) {
if(bls[i] == false) count++;
if(count == n) {
bls[i] = true;
count = 0;
}
}
}
}