Static String Return Type
Hello,
I have an array interface and I should write the methods for them,I have a question in the following method.
I should write a method String toString(int[] arr) that returns a string which, if printed, provides a niprint out of the array content. Used as:
int n = {3,4,5,6,7};
String str = Arrays.toString(n);
System.out.println("n = " + str);
I have written my method like this :
Code:
static String toString(int[] arr)
{
System.out.print("\n"+ "All the values in the array are: " );
int i;
String array = null;
for ( i = 0; i < arr.length; i++ )
{
array=Integer.toString(arr[i]);
System.out.print(" "+ array);
}
return " "+ array;
}
& the return type return NULL !I would like to know what I can I call as a return type.
Thanks all in advance.