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