Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help me out with this.

 
Shilpa Beri
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 210
Ruby Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15284
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic