判断是否是自守数 1、算出n的位数count 2、n*n % 10^count == n?true:false
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNextInt()) { // 注意 while 处理多个 case
int n = in.nextInt();
int sum = 0;
for(int i=0;i<=n;i++){
if(automorphicNumbers(i)){
sum++;
}
}
System.out.println(sum);
}
}
public static boolean automorphicNumbers(int n) {
int count = 1;//n的位数,至少是一位
int temp = n;
while(temp / 10 != 0){
count++;
temp /= 10;
}
if((n * n) % (Math.pow(10,count)) == n){
return true;
}
return false;
}
}