Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java BigNumber 2

 
Jose Carrillo
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi it's me again well when I say inicialized to zero I meant that that for example if the user enter a number for example 15 It won't appear 0000000015. IT has to be 15. I really I have not Idea how to do that I was planning with aloop but I have not Idea how to do it. if any one could help me I would appreciated. here es my code:
public class GiantNumber
{
private short[] digitsArray;
public GiantNumber()
{
digitsArray = new short [100];
}
public void add()
{
GiantNumber a = new GiantNumber(3);
GiantNumber b = new GiantNumber(5);
a.add(b);
}
public void add(GiantNumber b)
{
}
public GiantNumber(int i)
{
}
}
thanks!
 
Kim Kantola
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you say "It won't appear 0000000015" do you mean that you are having trouble displaying the value? Is this a question about how to print out the value?
 
Jose Carrillo
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No what I mean is let's say that the user input the number: 15, but since it is an array of 100 digits it would appear a bunh od zeros and then the 15 something like 0000000000000000000000000000000000015. I want to get rid of those zeros.BUT I DO NOT KNOW HOW. thanks.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see any code above that is concerned with displaying the number. If you were to post such code that you are working on, it might become easier to suggest a nudge in the right direction.
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For one thing, where is the least significant digit stored in your array? I'll assume that it's in the [0] position.
So to truncate the zeroes you need to find in your array the most significant digit of the number the array is supposed to represent. The most significant digit will be the one that has all zeroes proceeding it. So in the example you gave, 00000000015, the most significant digit is 1, and it may be found in the [1] position of your array (assuming 5 is in the [0] position). Once you have determined at which position your most significant digit is at in the array, then all you need to do is display the number from the most significant digit down to the least significant digit (the one in the [0] position of your array).
The small challenge for you will be coming up with an algorithm to scan your array and determine where in the array your most significant digit lies.
HTH
 
Kim Kantola
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yea, I agree with Dick, need to see some example code to have an idea of what you are trying to do. It's hard to understand what you are asking without an idea of the code you have so far.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic