In addition to Weibo, there is also WeChat
Please pay attention

WeChat public account
Shulou
2025-11-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how Java prints the number of daffodils within 1-1000. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Number of daffodils: the number of daffodils is a three-digit number, and the cubic sum of its numbers is equal to the three-digit number itself. For example, 370, 333, 73, 0000, 371 is a number of daffodils.
Note: to determine whether a three-digit number is a daffodil number, you must first get the three-digit number, ten digits and a hundred digits
Public class MyTest {public static void main (String [] args) {/ * print 1-1000 number of daffodils: for example, 153 "1" 1 "1" 5 "5" 5 "3" 3 "/ / definition mark, the starting value of daffodil number 0 int count = 0; / / to find out the number of daffodils less than 1000, first go through each number Because the number of daffodils is a three-digit number, for (int I = 100; I < 1000; iAccording +) {/ / take out the bit int g = I; / / take out ten digits int s = iUnix 10; / / take out the hundred digits int b = iAccord 100 / / determine whether the sum of cubes in each bit is equal to itself, and if so, print out the number if (g*g*g+s*s*s+b*b*b==i) {/ / if it is the number of daffodils, count plus a count++; System.out.println (I);}} System.out.println ("number of daffodils within 1000:" + count);}}
Output result:
one hundred and fifty three
three hundred and seventy
three hundred and seventy one
four hundred and seven
Number of daffodils within 1000: 4
This is the end of this article on "how to print the number of daffodils within 1-1000 in Java". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope





About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.