java水仙花数代码实现 java水仙花数编程题

求水仙花数的java程序代码

public class Daffodil {

我们提供的服务有:网站设计制作、成都网站制作、微信公众号开发、网站优化、网站认证、常熟ssl等。为上千余家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的常熟网站制作公司

/**

*

* @param

* @return void

* @param args

* desc

*/

public static void main(String[] args) {

for (int n = 100; n 999; n++) {

int a = n / 100;

int b = (n % 100) / 10;

int c = n % 10;

if(Math.pow(a, 3)+Math.pow(b,3)+Math.pow(c,3)==n){

System.out.println(n);

}

}

}

}

用Java写个关于“水仙花数”的程序?

按一下代码执行:

public class woo {

public static void main(String args[]) {

System.out.println("100-1000中的水仙花数有:");

for(int i=100;i1000;i++){

int single  = i%10;

int ten = i/10%10;

int hundred = i/10/10%10;

//水仙花数判断要求

if(i == (single*single*single+ten*ten*ten+hundred*hundred*hundred)){

System.out.println(i);

}

}

}

}

扩展资料:

水仙花数只是自幂数的一种,严格来说3位数的3次幂数才称为水仙花数。

一位自幂数:独身数

两位自幂数:没有

三位自幂数:水仙花数

四位自幂数:四叶玫瑰数

五位自幂数:五角星数

六位自幂数:六合数

七位自幂数:北斗七星数

八位自幂数:八仙数

九位自幂数:九九重阳数

十位自幂数:十全十美数

参考资料:

水仙花数——百度百科

如何用java实现任意位数的水仙花数?

你好,代码如下:

public class ShuiXianHua {

public static void calculate(int num) {

int[] nums;

int temp = 0, cur;

int min = (int) Math.pow(10, num - 1);

int max = (int) Math.pow(10, num) - 1;

for (int i = min; i = max; i++) {

temp = 0;

nums = new int[num];

cur = i;

for (int j = 0; j num; j++) {

nums[j] = cur % 10;

cur /= 10;

}

for (int j = 0; j nums.length; j++) {

temp += (int) Math.pow(nums[j], num);

}

if (temp == i) {

System.err.println(i);

}

}

}

public static void main(String[] args) {

System.out.println("6位的水仙花数:" );

calculate(6) ;

}

}


新闻名称:java水仙花数代码实现 java水仙花数编程题
URL标题:http://ybzwz.com/article/ddsschs.html