多位水仙花数

来源:互联网 发布:linux gcc安装 编辑:程序博客网 时间:2024/05/23 20:45
/** * 水仙花数 * */public class Daffodil {public static void main(String[] args) {int max = 9999 ; int min = 10 ; for(int x=min;x<max;x++){String temp = String.valueOf( x ) ;  int pow = temp.length() ; char[] chars = temp.toCharArray() ;int all = 0 ;  for(char c : chars){int a = Integer.parseInt( String.valueOf(c) ) ; all += Math.pow( a , pow ) ;}if(all == x){System.out.println( x + "是水仙花数" ) ;}}} }

0 0
原创粉丝点击