Determines whether an int number is a self-holding number

Source: Internet
Author: User

Self-guarding number
If the number of squares at the end of a number equals this number, then the number is called the self-hold number.
Obviously, 5 and 6 are a self-observing number (5x5=25 6x6=36), 25x25=625 76x76=5776, so 25 and 76 are two-bit self-guarding.
Detailed Description:
Interface description
Prototype:
public static Boolean isautomorphicnum (int num)

Input parameters:
Num needs to determine the number of
Output parameters (the memory area pointed to by the pointer is guaranteed to be valid):
No
return value:
True is the self-guarding number
False is not a self-defending number
Knowledge points involved:
Java language Basics: Digital processing

I wrote the program:

public static Boolean isautomorphicnum (int num) {/* here implements the function */string input = num + ""; String power = num * num + ""; SYSTEM.OUT.PRINTLN (num * num); if (Input.equals (Power.substring (Power.length ()-input.length ())) {return true;} return false;}

My own test case:

public void TestCase01 () {assertequals (demo.isautomorphicnum (0), true); Assertequals (Demo.isautomorphicnum (1), true) ; Assertequals (Demo.isautomorphicnum (5), True), Assertequals (Demo.isautomorphicnum (6), true); Assertequals ( Demo.isautomorphicnum (+), true); Assertequals (Demo.isautomorphicnum), true); Assertequals ( Demo.isautomorphicnum (376), true); Assertequals (Demo.isautomorphicnum (625), true); Assertequals ( Demo.isautomorphicnum (9376), true); Assertequals (Demo.isautomorphicnum), false); Assertequals ( Demo.isautomorphicnum (+), false); Assertequals (Demo.isautomorphicnum (999999999), false);}
My own test cases can be passed, but after submitting to the answer system, the system tests that a test case does not pass:


About the number of negative numbers and the largest int I have tested, whether the number of inputs is negative to the system's discriminant results do not affect, that is, seemingly negative numbers can not be self-guarding number, when the input is the largest int value: 999999999, my program can also determine the result, that is, false (not self-guarding).

I don't know what kind of situation I have not considered, please help.

Determines whether an int number is a self-holding number

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.