Example of Java implementation of narcissus number algorithm between 10-100000
This article mainly introduces the Java algorithm for finding the narcissus number between 10 and 100,000. It analyzes the concept of narcissus number and the corresponding Java algorithm implementation skills in the form of examples. Friends who need it can refer to it
The example in this article describes the Java algorithm for finding the narcissus number between 10 and 100,000. Share it with everyone for your reference, the details are as follows:
Daffodil number:
Concept: The daffodil number refers to an n-digit number ( n≥3), the sum of the nth power of the numbers on each digit is equal to itself. (For example: 1^3 + 5^3+ 3^3 = 153)
Algorithm idea analysis: We perform this algorithm in two steps; first: we make a method to find the number of digits in a number Function; second: we call this function to calculate prime numbers between 10 and 100000!
The specific code is given below (for reference only):
package javastudy; public class Testit1 { public static void main(String[] args) { for (int number = 100; number <= 100000; number++) { //求10到10000之间所有的素数,一个大的循环 int temp = number; //这步代码是为了让Getlength(number)不变 int sum = 0; for (int i = 0; i < Getlength(number); i++) { sum += Math.pow(temp % 10, Getlength(number)); //次方和相加 temp = temp / 10; } if (sum == number) { //判断是否相等 System.out.print(number+" "); } } } static int Getlength(int number) { //这个函数是为了求一个数字的位数 int i = 0; while (number / 10 > 0) { i++; number /= 10; } return i + 1; } }
operation result:
The above is the detailed content of Example of Java implementation of narcissus number algorithm between 10-100000. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6
Visual web development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1
Powerful PHP integrated development environment