当前位置:网站首页>For cycle: daffodil case
For cycle: daffodil case
2022-07-25 10:22:00 【anerl】
Daffodils case :
demand : Output all... In the console “ Narcissistic number
Problem description
What is? “ Narcissistic number ”?
The Narcissus count is a three digit number The number of daffodils 、 ten 、 The sum of the hundreds of digit cubes is equal to the original number Such as 123 :13+23+33=1+8+27=36±123 Not Narcissus Such as 371 :33+73+13=27+343+1=371=371 It's Narcissus
analysis ( use 371 Example )
How to find three digit numbers :
371 :1 It's the original number pair 10 The result of the remainder operation 371%10=1
How to find a three digit hundred digit number :
371 :3 Is the original number divided by 100 Result ( to be divisible by )371/100=3
How to find three digit ten digit numbers :
371 :371 By dividing by 10, Can be 7 Move to position ( Integers ) 371/10=3737 Through to 10 The value of the last digit can be obtained by performing the remainder operation 7 37%10=7 summary :371/ 10% 10 = 7
reflection : How to find the value in the specified bit of any number
First use the integer division operation to move the required number to one digit , Then use the remainder operation to get the value on the last bit 123456789, Divide first 10000 obtain 12345, Right again 10 Get surplus 5
Code :
public class forTest03 {
public static void main(String[] args) {
// Output the number of all daffodils : Traverse all three digits
for (int i =100;i<1000;i++){
// Get the value on each of the three digits before calculating
int ge = i%10;
int shi = i/10%10;
int bai = i/10/10%10;
// The judgment condition is to take the value on each of the three digits , After calculating the cube sum, compare it with the original number to see if it is equal
if (ge*ge*ge + shi*shi*shi +bai*bai*bai ==i){
// The number that meets the conditions is daffodil
System.out.println(i);
}
}
}
}
Comprehensive analysis of :
1. First establish a cycle
2. Take out the tens and hundreds of the three digits
3. Calculate whether the conditions are met , Output when conditions are met
边栏推荐
- Yiwen society, three necessary packet capturing tools for hackers
- Snake games
- 将 conda 虚拟环境 env 加入 jupyter kernel
- 安装mysql时,string the service 安装失败>mysql80启动失败
- Open virtual private line network load balancing
- Radio and multi selection buttons of swing components
- Simple addition calculator
- [untitled]
- Number theory -- negative Radix conversion
- Angr (I) - Installation
猜你喜欢
随机推荐
多线程——Runnable接口,龟兔赛跑
数组静态初始化,遍历,最值
Exception handling exception
Nodejs initial experience
Supervisor部署(离线部署需要提前下载部署包)
Frp反向代理部署
Redis和MongoDB的区别
Open virtual private line network load balancing
Pow(x,n)
测试基本概念
OSPF协议的配置(以华为eNSP为例)
Angr (V) - angr_ ctf
多线程——五大状态
Principle of struct2
Round to the nearest
Angr(四)——angr_ctf
史上最全面的UE4 文件操作,打开,读、写,增、删、改、查
Selenium 等待元素出现与等待操作可以执行的条件
Yiwen society, three necessary packet capturing tools for hackers
bug要素









