LanQiaoTestCodes/约数.java

26 lines
540 B
Java
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package LanQiaoOJ;
/*约数
* 题目描述
本题为填空题,只需要算出结果后,在代码中使用输出语句将所填结果输出即可。
如果整数 a是整数 b的整数倍则称 b是 a的约数。
请问,有多少个正整数是 2020的约数。*/
public class 约数 {
public static void main(String[] args) {
int count=0;//表示2020的约数的个数
for(int a=1;a<=2020;a++) {
if(2020%a==0) {
count++;
}
}
System.out.println(count);
}
}
/*
* 法二
* int a=1;
* while(a<=2020){
if(2020%a==0)
count++;
a++;
}
*/