案例:水仙花

水仙花

//需求:在控制台输出水仙花数(水仙花是一个三位数,它的个位十位百位的数字立方和等于原数)
public class HelloWorld{
    
    
    public static void main(String[] args){
    
    
        for(int i=100; i<=999; 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){
    
    
                System.out.println(i);
            }
        }
    }
}

猜你喜欢

转载自blog.csdn.net/taoyingle/article/details/115077202