import java.util.Arrays;
public class example
{
private int numbers[]; //instance variable
private String result;
public example()
{
numbers = new int[10];
Arrays.fill(numbers, 42);
}
public example(int[] array)
{
numbers = Arrays.copyOf(array, array.length);
}
//get and set methods
public void setNumbers (int numbers)
{
//setMethod
this.numbers = new int[numbers];
}
public int [] getNumbers()//get method
{
return numbers;
}
public String toString()
{
String result = new String();
int i;
for (i = 0; i < numbers; i++)
result = result + list[i] + "\n";
}
}
嘿伙计们,所以我的toString()
方法有问题。我的toString()
方法应该返回一个String
包含我的实例数组的元素,中间有制表符的元素。所以这就是我所拥有的