自守数
自守数
http://www.nowcoder.com/questionTerminal/88ddd31618f04514ae3a689e83f3ab8e
在[0,n]的区间挨个来尝试,用正则匹配来判断是否符合条件,简单的一匹
import java.util.Scanner; public class Test99 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { int n = scanner.nextInt(); int selfHoldNumber = 0; for (int i = 0; i <= n; i++) { if (((int) Math.pow(i, 2) + "").matches("[0-9]*" + i + "$")) { selfHoldNumber++; } } System.out.println(selfHoldNumber); } } }