In what way is the BigInteger constructor which accepts a string not working out for you?

Edited 4 Years Ago by ~s.o.s~: n/a

Comments
the constructor that receives a char array was definitly the right answer all along ;)

Convert it to long first using Long.parseLong() and then convert the long to BigInteger using BigInteger.valueOf(long val) .

Cheers! :)

Convert it to long first using Long.parseLong() and then convert the long to BigInteger using BigInteger.valueOf(long val)

This won't work if the string representation is outside the "long" data type range, which is one of the main motivation for using BigInteger...

thanks dear it worked, but isn't there any direct way for such a conversion??

There is no direct way to do these conversions given that like C++, Java doesn't support operator overloading.

Edited 4 Years Ago by ~s.o.s~: n/a

thanks dear it worked, but isn't there any direct way for such a conversion??

It worked. -.-

Edited 4 Years Ago by dantinkakkar: n/a

So? It still doesn't change the fact that it will fail for certain inputs as mentioned above and the worst thing is that regular tests which don't exercise the limits won't be able to uncover this problem.

Please don't provide sub-standard advice to beginners who wouldn't know the difference between "working" and "correct" code. It's a pity that my post, which tried to push adil in the right direction was downvoted. If someone wants to challenge my post above, I would be more than happy to provide reasons/discuss.

Edited 4 Years Ago by ~s.o.s~: n/a

He wanted to find out the value of something raised to the power of something, and those something's were well within long range. And by the way, please be a little more polite. I am not challenging your post.

Please don't conflate strong disagreement and resetment towards advice given with impoliteness.

Plus, my first post was meant to push OP to do a bit more research about BigIntegers and you pretty much handed the answer. Questions posted (especially by studnents) are much more about the learning involved in reaching the answer rather than "getting" the answer.

Well, I'm sorry for that, but you sounded like a little rude to me. So I hit back at you. Apologies for any mistake made by me.

Comments
No worries

i have researched it a lot but was not getting the right thing, so i need to take the help of the forum, and if anyone wants me to go on researching, then its useless for me to be in the forum. Sometimes the answers are to be handed away.

Comments
yeah
i disagree, being able to find answers on your own at your level is the best skill you can work on, if we hand you answers now, you will advanced to more advanced programming classes and find yourself on this forum asking for answers 24/7!
This question has already been answered. Start a new discussion instead.