2 Finish (5 points)
Topic content:
The factor of a positive integer is all positive integers that can be divisible by it. And if a number is exactly equal to the sum of factors other than itself, this number is called the end number. For example 6=1+2+3 (6 of the factor is the one-to-be).
Now you are going to write a program that reads two positive integers n and M (1<=n<m<1000) and outputs all the n,m in the range.
Tip: You can write a function to determine whether a number is complete.
Input format:
Two positive integers, separated by a space.
Output format:
In the meantime, all the numbers are separated by a space, and the last number has no space behind it. If not, a blank line is output.
Input Sample:
1 10
Sample output:
6
time limit: 500ms memory limit: 32000kb
Import Java.util.scanner;public class Main {public static void main (string[] args) {Scanner sc = new Scanner (system.in); T count = 0;//counter int n = 0;//reads in two positive integers n and m (1<=n<m<1000) int m = 0;n = Sc.nextint (); m = Sc.nextint (); for (int i = n; I <= m; i++) {if (Iswanshu (i)) {count++;if ((count! = 0) && (count! = 1)) {System.out.print ("");} System.out.print (i);}}} public static Boolean Iswanshu (int number) {//hint: You can write a function to determine whether a number is the end of a Boolean Wanshu = false;//is the sum of int sums = 0;//factor and for (int i = 1; i < number; i++) {if (number% i = = 0) {sum + = i;}} if (sum = = number) The factor of {//A positive integer is all positive integers that can be divisible by it. And if a number is exactly equal to the sum of factors other than itself, this number is called the end number. For example 6=1+2+3 (6 of the factor is the one-to-be). Wanshu = true;} else {Wanshu = false;} return Wanshu;}}
China MOOC_ 0 Basic Java language _ 7th week function _2 End number