The number of statistics in all 100 to 999 "number Narcissus" of

Ideas: the first to use a for loop through all the numbers between 100-999, then if satisfied bits plus cubic cubic cubic plus one hundred ten is equal to the original number, then the number is "the number of Narcissus", statistics variables ++;

Code:

public class Demo1 {
	public static void main(String[] args) {
		int count = 0;
		for(int i =100;i<1000;i++) {
			int a = i%10;
			int b = i/10%10;
			int c= i/10/10%10;
			if((a*a*a+b*b*b+c*c*c) == i ) {
				count++;
			}
		}
		System.out.println("水仙花数的个数为:"+count);
	}
}

effect:

Published 28 original articles · won praise 5 · Views 5804

Guess you like

Origin blog.csdn.net/weixin_41879980/article/details/95852501