File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Code for addition of two numbers? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Code for addition of two numbers?" Watch "Code for addition of two numbers?" New topic

Code for addition of two numbers?

Nagacharan Lokkidi

Joined: Jul 25, 2011
Posts: 9
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

Joined: Oct 14, 2005
Posts: 19847

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

Joined: Mar 20, 2007
Posts: 317
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.
I agree. Here's the link:
subject: Code for addition of two numbers?
jQuery in Action, 3rd edition