This Java program identifies integers within a given range that possess one or more of five special mathematical properties.
The program iterates from a start to an end value and checks each number against the following five properties. If a number matches at least one, it is printed to the console along with its properties.
- Harshad Number: A number that is divisible by the sum of its digits.
- Happy Number: A number that eventually reaches 1 when replaced by the sum of the square of its digits.
- Perfect Number: A number that is equal to the sum of its proper divisors. (This program identifies them using two different methods, named 'Nils' and 'Cordula').
- Hermann Number: A custom-defined number whose binary representation consists of
k+1ones followed bykzeros (fork >= 1).
- Navigate to the
srcdirectory. - Compile the Java file:
javac ueb/Main.java
- Run the program from the
srcdirectory:java ueb.Main
The program will then output the numbers in the range of -5 to 500 that match the criteria.