with integer arrays when i add them i can have code that looks like this
result[0] = array[0] + array2[0]
all the arrays being of integer type
now if my arrays are of Huge type and i would like to get their sum, how would i do that?
this is the code i have but i does not work. i c++ i would have used operator overloading to overload the "+" operator, i now know that there is no operator overloading in java
package HugeInterger;
public class HugeInterger
{
/*
randomly generate the object with random numbers from 1 to 9
*/
int length = 4;
int array[][] = new int[length][length];
public static int[][] Input(int array[][])
{
for(int row = 0; row < array.length; row++)
{
for(int column = 0;column < array[row].length; column++)
{
int randomNumber = 1 + ((int) (Math.random() * 9));
array[row][column] = randomNumber ;
}
}
return array;
}
public static void Output(int array[][])
{
/*
print out the results
*/
for(int row = 0; row < array.length; row++)
{
for(int column = 0; column < array[row].length; column++)
{
System.out.print(array[row][column] + " ");
}
System.out.println();
}
}
public static HugeInterger Add(HugeInterger array[][],HugeInterger array2[][])
{
/*
I now try to add the two object, this is where my problem is
*/
HugeInterger result[][] = new HugeInterger[array.length][array.length];
for(int row = 0; row < array.length; row++)
{
for(int column = 0; column < array[row].length; column++)
{
result[row][column] = array[row][column] + array2[row][column];
}
}
return result;
}
}
i get as error as "+" is not defined for my new object type