Nude Numbers in Java
In this section, we will discuss what is a nude number and also create Java programs to check if the given number is a nude number or not. The nude number program is frequently asked in Java coding interviews and academics.
A number is said to be nude number if all the digits of the number is the factor of that number. In short, nude numbers are those numbers that expose their factor.
672 is a nude number because all the digits (6, 7, and 2) of the number are the factors of the number itself.
Let's see another example.
101 is not a nude number because all of the digits of the number 101, i.e., 1 and 0, do not divide the number 101. Observe that 1 divides the number 101, but 0 does not divide the number. Thus, we got at least one digit that does not divide the number 101.
Nude Number Java Program
Let's see the implementation to find the nude number using while loop.
Nude numbers between 10 to 60 are: 11 12 15 22 24 33 36 44 48 55
We can also achieve the same result using recursion. The following program shows the same.
Nude numbers from 10 to 60 are: 11 12 15 22 24 33 36 44 48 55
Note: We know that every number is drivable by itself. Therefore, a single-digit number (except 0) is a nude number. For example, 1, 2, 3, …, 9 are nude numbers. Another point to note that a number multiplied by 0 is always 0. Therefore, 0 can never be a factor of any number. Hence, any number that contains 0 can never be a nude number.
Next TopicJava Programming Challenges