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 help me out with this. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "help me out with this." Watch "help me out with this." New topic

help me out with this.

Shilpa Beri

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


Wirianto Djunaidi
Ranch Hand

Joined: Mar 20, 2001
Posts: 210

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
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15092

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 8 API documentation
I agree. Here's the link:
subject: help me out with this.
It's not a secret anymore!