/**
 * {@link <a href=
 * "https://[Log in to view URL]"
 * target="_blank">Passaggio di un array, come parametro di un metodo o come tipo restituito</a>}
 * 
 * @author itammb ( Italia Massimiliano Buscati )
 * @version JDK 1.15
 *
 */
class Main {
	public static void toParameterPassingMethod(int[] array) {
		count(array);

		// int[] è passato al metodo come riferimento

		// ogni modifica dentro il metodo al int[], si ripercuote sulla variabile del
		// flusso principale 
		array[0] = 0;
	}

	private static void count(int[] array) {
		int count = 0;

		for (int i = 0; i < array.length; i++)
			System.out.println("elemento -> " + array[i] + " conteggio precedente -> " + count
					+ " conteggio attuale -> " + (count += array[i]));
	}

	public static int[] toReturnFunction() {
		return new int[] { 1, 2, 3 };
	}

	public static void main(String args[]) throws Exception {
		// Unit test - passaggio di un array come parametro di un metodo
		int array[] = { 1, 2, 3 };
		toParameterPassingMethod(array);
		System.out.println();
		count(array);

		System.out.println();

		// Unit test - int[] come tipo di ritorno di una funzione
		for(int numero : toReturnFunction())
			System.out.println(numero);
	}
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: