Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Code for addition of two numbers?  RSS feed

 
Nagacharan Lokkidi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, i need a addition program for adding two numbers which should take 1000 digits each number. If anybody knows this code,please help me.
Thanks in advance.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Normally one would just use BigInteger objects if one wanted to add together two integers with 1000 digits.

However I expect you are asking about some homework problem, in which case BigInteger wouldn't be acceptable. If that's the case, please read these links: DoYourOwnHomework and ShowSomeEffort, and then if you still have a question, don't hesitate to ask that question here.
 
Sridhar Santhanakrishnan
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Keep the numbers as two int arrays. Traverse the arrays and add the numbers moving the 'carry' to the preceeding index. Finally print the array.

Hope this helps.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!