/*Hello, I tried to write a array class for adding each element by 1, however I couldn't call the toString() method successfully, can anyone help me figure out why? Thanks.
package addArray;
public class Additioner {
public Additioner(int x[])
{
addIt(x);
}
public void addIt(int x[])
{
for (int counter = 0; counter < x.length; counter++)
{
x[counter] += 1;
}
}
public String toString()
{
String message = ("Some message here.");
return message;
}
}
============================================
package addArray;
import java.util.*;
public class Array {
public static void main(String[] args)
{
int Q[] = {1, 2, 3, 4, 5};
System.out.println(Arrays.toString(Q));
Additioner x = new Additioner(Q);
System.out.println(Arrays.toString(Q));
System.out.println(Q.toString());
} }
================================================== Result:
[1, 2, 3, 4, 5]
[2, 3, 4, 5, 6]
[I@6d06d69c