Determines whether an int-type number is an autonomous number.

Source: Internet
Author: User

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.

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.