Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class dividesSelf {
- static boolean divide(int n) {
- int number = n;
- if ((number / 100) / number == 0 && (number / 100) != 0) { // 1
- if ((number % 100) / 10 == 0 && ((number % 100)/10) != 0) { // 2
- if (number % 10 != 0) { // 2
- return true;
- }
- }
- } else { // If there is a 0 in the hundreds place, check on the tens and ones place...
- if((number / 100) != 0) { // check the hundreds place to see if there is a 0.
- if (((number % 100)/10) == 0) { // then check the tens place
- if (number % 10 != 0) { // then check the ones place
- return true;
- }
- }
- }
- return false; // if other conditions exist, return false
- }
- return false;
- }
- public static void main(String[] args) {
- System.out.println(divide(122));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement