📄 sxhs2.java
字号:
import java.io.*;
public class Sxhs2{
static int n;
//static int[] Ai;
public static void main(String[] args){
System.out.println("请输入所求水仙花数的位数n(n>=3):");
try{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
String inputLine=in.readLine();
n=Integer.valueOf(inputLine).intValue();
}catch(Exception e){
System.out.println("输入不合法");
return;
}
//Ai=new int[n];
Sxhs2 Sx=new Sxhs2();
Sx.GetResult(n);
}
//static int n;
//int[] Ai=new int[n];
public void GetResult(int p){
//double num=0;
for(double i=Math.pow(10,(p-1));i<Math.pow(10,p);i++){
//int n=0;
int j=1;
double x=0;
double total=0;
while(j<=i){
j*=10;
//n++;
}
while(j>=10){
x=(i%j)/(j/10);
total=total+Math.pow(x,p);
j=j/10;
}
if(total==i){
System.out.println(total);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -