Java calculates the _java of the number of self power and Narcissus

Source: Internet
Author: User
Tags pow

(For example: when n is 3 o'clock, there is a 1^3 + 5^3 + 3^3 = 153,153 is a power number when n is 3)
N is 1 o'clock, the self power number is called a single number.
N is 2 o'clock, there is no power number.
N is 3 o'clock, and the self power number is called the Narcissus number.
N is 4 o'clock, and the self power number is called the number of roses.
N is 5 o'clock, and the self power number is called the pentagram number.
N is 6 o'clock, and the self power number is called the Liuhe number.
N is 7 o'clock, and the self power number is called the Beidou seven-star number.
N is 8 o'clock, and the self power number is called the Baxian number.
N is 9 o'clock, and the self power number is called the number of 99 Chongyang.
N is 10 o'clock, the self power number is called a perfect number.

Copy Code code as follows:

/*
* Self-Power number
* A power number is a n-digit number, its each bit of the number of the N power of the sum equals it itself.
* (for example: when n is 3 o'clock, there is 1^3 + 5^3 + 3^3 = 153,153 is a power number when n is 3)
*/
Import Java.util.Scanner;

public class self-power number {

public static void Main (string[] args) {
Scanner input = new Scanner (system.in);
System.out.println ("Please enter the number of self power digits you want to check:");
int n = input.nextint ();//receiving number of digits
Define a number, starting from 10^ (n-1), to 10^n end
Switch (n) {
Case 1:
System.out.println ("single number:");
System.out.print ("0" + "t");
Break
Case 2:
System.out.println ("Two-bit self-power number:");
System.out.println ("No power number!") ");
Break
Case 3:
System.out.println ("Narcissus number:");
Break
Case 4:
System.out.println ("Number of Roses:");
Break
Case 5:
System.out.println ("The number of Pentagram:");
Break
Case 6:
System.out.println ("Liuhe number:");
Break
Case 7:
System.out.println ("The Big Dipper Number:");
Break
Case 8:
System.out.println ("Baxian number:");
Break
Case 9:
System.out.println ("99 Chongyang Number:");
Break
Case 10:
System.out.println ("Perfect number:");
Break
Default
System.out.println ("Other Self Power Number:");
Break
}
for (int number = (int) Math.pow (n-1); number < Math.pow (n); number++) {
Judge Condition: Digit number number is n
if (string.valueof (number). Length () = N) {
Double num = 0;
for (int i = 0; i < n; i++) {
int temp = (int) (NUMBER/MATH.POW (i))% 10;
num + + MATH.POW (temp, n);
}
if (number = num) {
System.out.print (number + "T");
}
}
}
Input.close ();
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.