Hello,
below is my code
and the output/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package myproject; /** * * @author User */ public class Helloworld { /** * @param args the command line arguments */ public static void main(String[] args) { int[] a = new int[5]; int[] b = new int[5]; a=doIt(a); f(b); System.out.println("ARRAY a"); for(int i = 0; i < a.length; ++i) System.out.println(a[i]); System.out.println("ARRAY b"); for(int i = 0; i < b.length; ++i) System.out.println(b[i]); } public static int[] doIt(int[] var) { var = new int[15]; for(int i = 0; i < var.length; i++) { var[i] = i; } return var; } public static void f(int[] var) { var = new int[15]; for(int i = 0; i < var.length; i++) { var[i] = i; } } }
ARRAY a 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ARRAY b 0 0 0 0 0
This means that function f does not modify array b at all.Am i right?I need a reference to array b in order to have function f does the same job as function doIt,right?