Determines whether an int-type number is an autonomous number.
Self-defense
If the number of digits at the end of a number square is equal to this number, this number is called the number of self-defense.
Obviously, 5 and 6 are a number of self-defense (5x5 = 25 6x6 = 36), 25x25 = 625 76x76 = 5776, so 25 and 76 are two self-defense numbers.
Detailed description:
Interface Description
Prototype:
Public static boolean isAutoMorphicNum (int num)
Input parameters:
Num number to be determined
Output Parameters (the memory area pointed to by the pointer is valid ):
None
Return Value:
True indicates the number of guards.
False is not the number of self-defense instances.
Knowledge points:
JAVA language basics: Digital Processing
My programs:
Public static boolean isAutoMorphicNum (int num) {/* implement the function here */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 cases:
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(25) ,true);assertEquals(Demo.isAutoMorphicNum(76) ,true);assertEquals(Demo.isAutoMorphicNum(376) ,true);assertEquals(Demo.isAutoMorphicNum(625) ,true);assertEquals(Demo.isAutoMorphicNum(9376) ,true);assertEquals(Demo.isAutoMorphicNum(10), false);assertEquals(Demo.isAutoMorphicNum(100) ,false);assertEquals(Demo.isAutoMorphicNum(999999999) ,false);}My own test cases can pass, but after I submit it to the Q & A system, the system test says that one test case fails:
I have tested the negative number and the maximum int number. Whether the input number is a negative number does not affect the system's discriminant result. That is, it seems that a negative number cannot be an independent number, when the input is the maximum int value: 999999999, my program can also determine the result, that is, false (not the number of self-defense ).
I don't know what else I haven't considered. Please help.