-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
public class java循环嵌套计算水仙花 { | ||
public static void main(String[] args) {//主函数 | ||
int 最大值=9999;//最大值 | ||
int 最小值=1;//最小值 | ||
|
||
for(;最小值<=最大值;最小值++) {//循环所有数值 | ||
int 位数=计算数的位数(最小值); | ||
int 真假水仙花=0; | ||
//int aa=0; | ||
//System.out.println("x="+x); | ||
int 当前计算的数=最小值; | ||
//int y=1; | ||
for(int 这个数的某位;当前计算的数!=0;/*y++*/) {//循环这个数的每位 | ||
这个数的某位=当前计算的数%10; //获取每一位 | ||
当前计算的数=当前计算的数/10; //整数退一位 | ||
int 某位的位数次方=这个数的某位; | ||
//System.out.println("第"+y+"位数是"+num); | ||
for(int 乘以位数减一=1;乘以位数减一<位数;乘以位数减一++){ | ||
某位的位数次方*=这个数的某位; | ||
} | ||
真假水仙花+=某位的位数次方; | ||
//System.out.println("第"+y+"位数次方是"+yy); | ||
} | ||
//System.out.println("这位数的每位数位数次方相加是"+aaa); | ||
if(真假水仙花==最小值) { | ||
System.out.print("水仙花:"+最小值+"\n"); | ||
} | ||
} | ||
} | ||
|
||
public static int 计算数的位数(int 计算的值) { | ||
int 位数=0; | ||
for(;计算的值>=1;位数++) { | ||
计算的值/=10; | ||
} | ||
return 位数;//返回位的数量 | ||
} | ||
} |