-6

I want to calculate(sum) with very large two numbers But when I use Scanner method there was the IOException when I input very large numbers. There are some rules.

  • I can't use BigInterger
  • I can use only purely integer.
  • I can use InputStream.

Please give me solutions.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • Your question embodies a contradiction in terms. Integers have a finite range. Unless 'very large', whatever that means, is within that range, the task is self-evidently impossible. – user207421 Sep 22 '12 at 09:57
  • Since you "can't use BigInteger" and other apparently arbitrary constraints, I presume this is homework? If so, please tag it as such. – DNA Sep 25 '12 at 15:51

1 Answers1

2

I'm assuming that this is a competition, homework or self learning exercise, and that complete solutions would be self-defeating.

You need to work out a way to represent large numbers as arrays of smaller numbers, then do arithmetic using this representation. This is essentially what BigInteger does under the hood. Think about how you do arithmetic with a pencil and paper, and generalize that.

And if your puzzle doesn't allow you to use arrays, you could simulate them (horribly inefficiently) with input and output streams.

But I'm coming to the conclusion that this is not a real question at all ...

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216