aspose file tools*
The moose likes Beginning Java and the fly likes Java BigNumber Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java BigNumber" Watch "Java BigNumber" New topic
Author

Java BigNumber

Jose Carrillo
Greenhorn

Joined: Nov 13, 2003
Posts: 17
Hello well I have to make a BigNumner class that store 100 digits using and array where each element of the array will represent a digit. my question is I have declare the array to 100 elements and then I have to incialized to zero and I do not have any idea how to do that this my code so far:
Public class GiantNumber
{
private short [] digitsArray;

public GiantNumber()
{
digitsArray = new short[100];
}
public GiantNumber1()
{
//here I have to include a default constructor that initializes our number to 0
}
}
I really apreciated
Sadanand Murthy
Ranch Hand

Joined: Nov 26, 2003
Posts: 382
Originally posted by Jose Carrillo:
Hello well I have to make a BigNumner class that store 100 digits using and array where each element of the array will represent a digit. my question is I have declare the array to 100 elements and then I have to incialized to zero and I do not have any idea how to do that this my code so far:
Public class GiantNumber
{
private short [] digitsArray;

public GiantNumber()
{
digitsArray = new short[100];
}
public GiantNumber1()
{
//here I have to include a default constructor that initializes our number to 0
}
}
I really apreciated


Looks like you are jumping into coding without quite grasping the java programming concepts. Please take a look at the Sun's Java Tutorial.
For a class called GiantNumber you cannot have a constructor called GiantNumber1. The constructor name must be exactly the same as the class name. So you will need to use overloading concepts to create multiple constructors for a class.
You reference an element in an array by using the form 'myArray[i]' which will access the i'th element of the array called myArray. If the array is made of primitives, you can assign each element of the array value 0 (or anything else) by using the form 'myArray[i] = 0;'. Since in your case you have 100 array elements, you will need to use a loop (a for loop fits great for this).
A final point - arrays in java are 0 based.
That is why I said at the outset that you need to go through the tutorial.


Ever Existing, Ever Conscious, Ever-new Bliss
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
Primitives are automatically initialized to 0. Each element in an array of primitives is likewise initialized to 0. Therefore you do not need to do any initialization on your array of shorts if you simply want each element to be 0.

Was this your question or did I misunderstand you?
As a side note, you cannot have two empty constructors, and any constructor you do have must have the same name as your class. So given your code, you cannot have the constructor GiantNumber1().
[ February 03, 2004: Message edited by: Jason Menard ]
 
jQuery in Action, 2nd edition
 
subject: Java BigNumber