Java 自守数
【摘要】
import java.util.Scanner; public class zishoushu { public static void main(String[] args) { Scanner sc=new Scanner(System.in); long x=sc.nextInt(); if(zishou(x)==1){ System.out.p...
-
import java.util.Scanner;
-
-
public class zishoushu {
-
public static void main(String[] args) {
-
Scanner sc=new Scanner(System.in);
-
long x=sc.nextInt();
-
if(zishou(x)==1){
-
System.out.println("您输入的数"+x+"是自守数");
-
}else{
-
System.out.println("您输入的得数"+x+"不是自守数");
-
}
-
System.out.println("以下是1000以内自守数");
-
for(int i=2;i<1000;i++){
-
if(zishou(i)==1){
-
System.out.print(i+" ");
-
}}
-
-
}
-
public static int zishou(long n){
-
long temp,k,m;
-
int count;
-
k=1;
-
count=0;
-
while(k>0){
-
k=n-(long)Math.pow(10, count);
-
count++;
-
}
-
m=count-1;
-
temp=(n*n)%((long)Math.pow(10,m));
-
if(n==temp) return 1;
-
return 0;
-
}
-
}
文章来源: czhenya.blog.csdn.net,作者:陈言必行,版权归原作者所有,如需转载,请联系作者。
原文链接:czhenya.blog.csdn.net/article/details/77610666
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)