
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Java Program to check if all digits of a number divide it
To check if all digits of a number divide it, the Java code is as follows −
Example
import java.io.*; public class Demo{ static boolean divisibility_check(int val, int digit){ return (digit != 0 && val % digit == 0); } static boolean divide_digits(int val){ int temp = val; while (temp > 0){ int digit = val % 10; if ((divisibility_check(val, digit)) == false) return false; temp /= 10; } return true; } public static void main(String args[]){ int val = 150; if (divide_digits(val)) System.out.println("All the digits of the number divide the number completely."); else System.out.println("All the digits of the number are not divided by the number completely."); } }
Output
All the digits of the number are not divided by the number completely.
A class named Demo contains a function named ‘divisibility_check’, which has two parameters- the number and the digit. This function returns a Boolean value depending on whether the output returned is true or false. It checks if the number is not 0 and if the number divided by digit of the number is completely divided or not.
Another function named ‘divide_digits’ is a Boolean function that takes the number as the parameter. This function checks to see if all the digits in a number divide the number fully. In the main function, a value for the number is defined and the function is called with this value, if it returns ‘true’, then relevant message is displayed. If not, then it gives a message stating the number can’t be completely divided.
- Related Articles
- C Program to Check if all digits of a number divide it
- PHP program to check if all digits of a number divide it
- Python Program for Check if all digits of a number divide it
- Check if all digits of a number divide it in Python
- C++ Program to check if a given number is Lucky (all digits are different)
- Java Program to check whether it is possible to make a divisible by 3 number using all digits in an array
- Java Program To Reverse A Number And Check If It Is A Palindrome Number
- C Program to check if a number is divisible by sum of its digits
- C Program to check if a number is divisible by any of its digits
- Java Program to Check if a given Number is Perfect Number
- Check if the frequency of all the digits in a number is same in Python
- Python Program to check whether it is possible to make a divisible by 3 number using all digits in an array
- C/C++ Program to check whether it is possible to make a divisible by 3 number using all digits in an array?
- Java Program to check if a string is a valid number
- Java Program for check if a given number is Fibonacci number?
