Liutauras Vilda wrote:The goal of the method is not clear. Please explain exactly what has to be achieved.
Z Howard wrote:
Carey Brown wrote:
Z Howard wrote:
For any positive value of N this will return 1. Is this really what you want?
"2^n" is "2 xor n". This does not raise 2 to the power of N. Is this really what you want?
Don't program nothing yet. Try to solve this first on a piece of paper. It doesn't seem you understand yourself those formulas and what you need to calculate.Z Howard wrote:Im not entirely sure but I need to calcuate the square root of a power of 2? So 2^n , but how would I program this
Liutauras Vilda wrote:Are you able to use existing classes and methods in Java? Or you need to implement those methods yourself (sqrt, pow)?
Z Howard wrote:I have to calculate the power using a for or while loop to multiply 2 by itself n times. (Use double)
And I have to find the sqrt by using Math.sqrt
Z Howard wrote:Im required to implement these methods myself.
I'm afraid not.Z Howard wrote:I have worked out a method to calculate the square root and 2^n
You reused existing method Math.pow from standard library. You said you have to implement yourself that one. N number cannot be fixed, in my opinion user suppose to have an ability to specify it. The current implementation also skips zero, where 2^0 is 1.Z Howard wrote:Im required to implement these methods myself.
Don't know. You didn't tell exact requirements.Z Howard wrote:Im sure some of this doesn't look right. Is it because ive misplaced Math.sqrt?
You have been told that too. Do one thing at a time.Z Howard wrote:I want to print math.pow and math.sqrt separate.
“Give a man a program, frustrate him for a day.
Teach a man to program, frustrate him for a lifetime.”
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |