Given a number n, find whether all digits of n divide it or not.
Input : 128 Output : Yes 128 % 1 == 0, 128 % 2 == 0, and 128 % 8 == 0. Input : 130 Output : No
We want to test whether each digit is non-zero and divides the number. For example, with 128, we want to test d != 0 && 128 % d == 0 for d = 1, 2, 8. To do that, we need to iterate over each digit of the number.
Please refer complete article on Check if all digits of a number divide it for more details!
- Java Program to check whether it is possible to make a divisible by 3 number using all digits in an array
- Java Program to Handle Divide By Zero and Multiple Exceptions
- Java Program to Increment by 1 to all the Digits of a given Integer
- Java Program for Sum the digits of a given number
- Java Program to Reverse a Number and find the Sum of its Digits Using do-while Loop
- How to check if string contains only digits in Java
- Java Program for How to check if a given number is Fibonacci number?
- Check if the given decimal number has 0 and 1 digits only
- Java ArrayList to print all possible words from phone digits
- Java Program for Difference between sums of odd and even digits
- Java Program to Extract Last two Digits of a Given Year
- Java Program to Extract Digits from A Given Integer
- Java Program to check Armstrong Number
- Java program to check if a number is prime or not
- Java Program to Reverse a Number & Check if it is a Palindrome
- Java Program to Check Whether Number is Divisible by 5
- Java Program for efficiently print all prime factors of a given number
- Java Program to Find the Number Occurring Odd Number of Times
- Java Program to Convert a Decimal Number to Binary & Count the Number of 1s
- TCS Coding Practice Question | Sum of Digits of a number