Main program algorithm
1. Start.
2. Read input:
Prompt and read integer m (lower limit).
Prompt and read integer n (upper limit).
3. Validate input:
If m >= n, print "INVALID INPUT" and exit.
4. Initialize counters/flags:
count← 0 - number of automorphic numbers found.
k ← true - a boolean to control comma placement.
5. Print header text: "THE AUTOMORPHIC NUMBERS ARE: ".
6. For every integer i from m to n (inclusive):
a. Call isAutomorphic(i)
b. If isAutomorphic(i) returns true:
If k is false, print a comma, before printing the next number (to separate values).
Print the value i
Set k ← false.
Increment count by 1.
7. After the loop:
If count == 0, print "NIL" (means no automorphic numbers found).
8. Print newline and then "FREQUENCY OF AUTOMORPHIC NUMBERS IS: + count.
9. End.
isAutomorphic(num) function algorithm
Purpose: return true if the last digits of num * num equal num.
1. Compute square: square ← num * num.
2. Compute modulus base temp equal to 10 raised to the power of d where d is the number of digits in num:
Initialize temp ← 1.
Let t ← num.
While t > 0:
temp ← temp * 10
t ← t / 10
After loop, temp equals 10 raised to the power of (number_of_digits_in_num).
3. Compare last d digits:
Compute square % temp. If square % temp == num, return true, else return false.
A number is called an automorphic number if its square ends with the number itself.
For example: 5² = 25, 6² = 36, 25² = 625 — all end with themselves.
Write a program in Java to input two positive integers m and n (m < n) and:
Display all automorphic numbers between m and n (inclusive).
Display their frequency.
If m ≥ n, display “INVALID INPUT”.