# help me out with this.

Shilpa Beri

Greenhorn

Posts: 2

posted 10 years ago

hello friends

new to java world, just learning. help me with this problem i am struck up.

I am trying to write a program that multiplies two large integers.

here is my code but i am getting array index out of bounds.

just let me know how to resolve that arrayindex out of bounds problem

thanks

shilpa

new to java world, just learning. help me with this problem i am struck up.

I am trying to write a program that multiplies two large integers.

here is my code but i am getting array index out of bounds.

just let me know how to resolve that arrayindex out of bounds problem

thanks

shilpa

posted 10 years ago

Your problem is at the

your som started with value of 8,

in the first iteration of i, where i = 3, you have som=som-i which is 5.

then you get into j loop, which has som-- in each iteration, where you end up with som = 3 at the end of all iteration.

in the second iteration of i, where i = 2, you have som = som - i which 3 - 2 = 1.

After first iteration of j, with the som--, you end up with som =

After second iteration of j, with the som--, you end up with som =

You need to rethink your algorithm again so

Hope that helps.

[ October 11, 2005: Message edited by: Wirianto Djunaidi ]

**som**variable. Please you pay attention to**som**calculation in the the nested loop.your som started with value of 8,

in the first iteration of i, where i = 3, you have som=som-i which is 5.

then you get into j loop, which has som-- in each iteration, where you end up with som = 3 at the end of all iteration.

in the second iteration of i, where i = 2, you have som = som - i which 3 - 2 = 1.

After first iteration of j, with the som--, you end up with som =

**0**.After second iteration of j, with the som--, you end up with som =

**-1**. Which is outside of range of your array.You need to rethink your algorithm again so

**som**will be inside valid value range.Hope that helps.

[ October 11, 2005: Message edited by: Wirianto Djunaidi ]

posted 10 years ago

Interesting program, but did you know that Java already has standard classes for working with integers with an arbitrary number of digits and floating point numbers with arbitrary precision?

Have a look at the documentation of the classes java.math.BigInteger and java.math.BigDecimal.

Have a look at the documentation of the classes java.math.BigInteger and java.math.BigDecimal.