问几个最基本的问题
Test1:
public class TestArray
{
public TestArray()
{
}
public void testA(float[] a)
{
float[] b=new float[a.length];
for(int i=0;i<b.length;i++)
b[i]=i*i;
a=b;
System.out.println("first "+b[1]) ;
System.out.println("second "+a[1]) ;
}
public static void main(String[] args)
{
float[] a={1.1f,2.2f,3.3f};
TestArray object=new TestArray();
object.testA(a);
System.out.println("third"+a[1]);
}
}
结果是
first 1.0
second 1.0
third 2.2
Test2
public class TestArray
{
public TestArray()
{
}
public void testA(float[] a)
{
float[] b=new float[a.length];
for(int i=0;i<b.length;i++)
b[i]=i*i;
for(int i=0;i<b.length;i++)
a[i]=b[i];
System.out.println("first "+b[1]) ;
System.out.println("second "+a[1]) ;
}
public static void main(String[] args)
{
float[] a={1.1f,2.2f,3.3f};
TestArray object=new TestArray();
object.testA(a);
System.out.println("third "+a[1]);
}
}
结果是
first 1.0
second 1.0
third 1.0
Test3
public class TestArray
{
public TestArray()
{
}
public void testA(float[] a)
{
float[] b=new float[a.length];
for(int i=0;i<b.length;i++)
b[i]=i*i;
for(int i=0;i<b.length;i++)
a[i]=b[i];
System.out.println("first "+b[1]) ;
System.out.println("second "+a[1]) ;
}
public static void main(String[] args)
{
float[][] x=new float[3][10];
System.out.println("third "+x[0][1]);
TestArray object=new TestArray();
object.testA(x[0]);
System.out.println("third "+x[0][1]);
}
}
结果是
third 0.0
first 1.0
second 1.0
fourth 1.0
Test4
public class TestArray
{
public TestArray()
{
}
public float[] testA(float[] a)
{
return a;
}
public static void main(String[] args)
{
float[] x={1.1f,2.2f,3.3f};
float[] y=new float[3];
TestArray test=new TestArray();
y=test.testA(x);
System.out.println(y[1]);
}
}
结果是
2.2
Test5
public class TestArray
{
public TestArray()
{
}
public void testA(Integer a)
{
Integer b=new Integer(10);
a=b;
System.out.println("first "+b) ;
System.out.println("second "+a) ;
}
public static void main(String[] args)
{
Integer a=new Integer(1);
TestArray object=new TestArray();
object.testA(a);
System.out.println("third "+a);
}
}
结果是
first 10
second 10
third 1
我觉得test1不好理解。好象和下面的比如test4矛盾呀。它究竟传递了什么东西过去?
那位帮忙讲一下java的机理,我对c++的指针太习惯了,对java就很不习惯呵呵。