• 周四. 10 月 3rd, 2024

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

Find the number of Narcissus in 100 ~ 999 in Java

King Wang

1 月 3, 2022

Java seek 100~999 The number of daffodils :

package mqday02_2019;
public class Demo14 {
public static void main(String[] args) {
// TODO Auto-generated method stub
// Output 100~999 The number of daffodils
int a=0;
System.out.println("100~999 The number of daffodils is :");
for(int i=100;i<=999;i++) {
int bw=i/100; // Find the hundred digit number
int sw=i%100/10; // Find the ten digit number
int gw=i%10; // Find a bit value
int sum=bw*bw*bw+sw*sw*sw+gw*gw*gw; // The sum of the cubes of the digits
if(sum==i){ // The sum of cubes is equal to the number itself , The number of daffodils
a++;
System.out.println(i);
}
}
System.out.println("100~999 Total number of daffodils :"+a);
}
}

发表回复