can any one give me the source code using java?

45 pts.
Tags:
Application development
Java
Write a function named isSquare that returns 1 if its integer argument is a square of some integer, otherwise it returns 0. Your function must not use any function or method (e.g. sqrt) that comes with a runtime library or class library! The signature of the function is int isSquare(int n) Examples: if n is return reason 4 1 because 4 = 2*2 25 1 because 25 = 5*5/td> -4 0 because there is no integer that when squared equals -4. (note, -2 squared is 4) 8 0 because the square root of 8 is not an integer. 0 1 because 0 = 0*0

Answer Wiki

Thanks. We'll let you know when a new response is added.

If you cannot use ANY function, your function should look something like this:

<pre> public int isSquare (int n) {
int iRootTest = 1;
int iSquareTest = 0;
if (n == 0 || n == 1)
return 1;
while (iSquareTest <= n) {
iSquareTest = iRootTest*iRootTest;
if (iSquareTest == n)
return 1;
iRootTest += 1;
};
return 0;
};</pre>

This function will try any integer starting from 1 until the square of that integer is equal or greater than n. If it is equal, then return 1, and when it is bigger exits from the loop and return 0;

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following