Java implements a specific range of complete output algorithm examples
This article describes the Java implementation of a specific range of completion output algorithm. Share with you for your reference, as follows:
Title Content:
The factor of a positive integer is all positive integers that can divide it. If a number is exactly equal to the sum of factors other than itself, it is called a perfect number.
For example, 6 = 1 + 2 + 3 (the factor of 6 is 1,2,3).
Now, you have to write a program to read in two positive integers n and m (1 < = n < m < 1000) and output all perfects in the range of [n, M].
Tip: you can write a function to judge whether a number is perfect.
Input format:
Two positive integers separated by spaces.
Output format:
All perfects are separated by spaces, and there is no space after the last number. If not, an empty line is output.
Input example: 1 10 output example: 6
Code example:
Operation results:
For more information about Java algorithms, readers who are interested can see the topics on this site: Java data structure and algorithm tutorial, summary of Java DOM node operation skills, summary of java file and directory operation skills, and summary of Java cache operation skills