当前位置:网站首页>Find daffodils - for loop practice

Find daffodils - for loop practice

2022-04-23 14:26:00 Zinksl

:::info
according to Forgetting curve : If there is no record and review ,6 Days later, I will forget 75% The content of
Reading notes are a tool to help you record and review , Don't stick to form , Its core is : Record 、 Look over 、 reflection
:::

Narcissistic number (Narcissistic number) It's also called super perfect number invariant (pluperfect digital invariant, PPDI)、 Narcissistic number 、 Self idempotent 、 Armstrong number or Armstrong number (Armstrong number), The number of Narcissus refers to a 3 digit , Of the numbers in each of its bits 3 The sum of the powers is equal to itself .

Case needs

demand 1 Find out the number of all daffodils

1 adopt for Loop through three digits
2 adopt if According to the concept of narcissus number , The number of daffodils in the sun

  //for Cycle to find the number of daffodils 
        for (int i=100;i<=999;i++){
    
            int ge,shi,bai; // Define everyone 、 ten 、 Hundreds of variables are ready for subsequent operations 
            ge = i%10;
            shi = i/10%10;
            bai = i/100;
            // use if The conditions of daffodil number were screened 
            if (i==(ge*ge*ge+shi*shi*shi+bai*bai*bai)){
    
                System.out.println(" Narcissistic number :"+i);
            }
        }

Conclusion

If there are any questions in the text , Welcome to correct , Welcome to discuss
See here , Just order a compliment and go ღ( ´・ᴗ・` ) finger heart  Insert picture description here

版权声明
本文为[Zinksl]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231412046288.html