一道简单的JAVA算法分析
各位大侠,请帮忙分析下面一段代码,为什么每次循环完后,a1[i]和a2[i]的值相等?a2[i]循环过程有有自增,但是a1[i]没有啊?为什么他们的值相等?package Javaweb;
public class shuli {
public static void main(String[] args){
int[] a1={2,3,4,7,8,9};
int[] a2;
a2=a1;
for(int i=0;i<a1.length;i++){
a2[i]++;
System.out.println("a1["+i+"]="+a1[i]);
System.out.println("a2["+i+"]="+a2[i]);
}
}
}
--------------------编程问答-------------------- package Javaweb;
public class shuli {
public static void main(String[] args){
int[] a1={2,3,4,7,8,9};
int[] a2;
a2=a1;
for(int i=0;i<a1.length;i++){
a2[i]++;
a1[i]++;
System.out.println("a1["+i+"]="+a1[i]);
System.out.println("a2["+i+"]="+a2[i]);
}
}
补充:.NET技术 , C#