Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Clock test
import java.util.ArrayList;
public class Reversible implements IReversible {
public ArrayList<Integer> listReversible(int upperLimit) {
ArrayList<Integer> list = new ArrayList();
for(int i = 0; i < upperLimit; i++) {
boolean found = true;
if(i % 10 != 0) {
if(allDigitsOdd(i + reverseNumber(i))) {
list.add(i);
}
}
}
return list;
}
public int reverseNumber(int number) {
int flip = 0;
while( number != 0 ) {
flip = flip * 10;
flip = flip + number%10;
number = number/10;
}
return flip;
}
public boolean isOdd(int number) {
if(number%2 == 0)
return false;
else
return true;
}
public boolean allDigitsOdd(int number) {
while(number > 0) {
int digit = number % 10;
if(!isOdd(digit))
return false;
number = number / 10;
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.