Monday 30 October 2017

Java array is lost when exiting method

I'm relatively new to java, and the passing by reference
without pointers confuses me a little. I wrote a function for homework that requires me
to return the length of user input, and assign use input to an array that is passed in,
when the method exits the user input array is lost, what is
wrong.



public static int
readArray(char[] intoArray)
{
char[] capture =
captureInputAsCharArray(); //User input comes back as char[]

System.arraycopy(intoArray,0, capture, 0,
capture.length);


return capture.length;

}

public static main(String[] args)
{
size =
readArray(arrItem7); // item 7
System.out.println(size);

printOneInLine(arrItem7); // prints individual elements of
array
}

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...