| Author |
help me out with this.
|
Shilpa Beri
Greenhorn
Joined: Oct 11, 2005
Posts: 2
|
|
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
|
 |
Wirianto Djunaidi
Ranch Hand
Joined: Mar 20, 2001
Posts: 195
|
|
Your problem is at the 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 ]
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12929
|
|
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.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
 |
|
|
subject: help me out with this.
|
|
|