定义一个类:class Test{
int a;
int[] arr;
}之后实例化这个数组Test test = new Test();
test.a =10;
//test.arr  ???????
//这里怎么给arr赋初值啊   举个列子 谢谢

解决方案 »

  1.   

    可以直接这样写:test.arr[0];test.arr= new int[]{2,5,7};......
      

  2.   

    class Test{
    int a;
    int[] arry;
    }
    public class FirstClass { /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    Test tc=new Test();
    tc.a=10;
    tc.arry=new int[10];
    for(int i=0;i<10;i++)
    tc.arry[i]=i+1;
    for(int i=0;i<10;i++)
    System.out.print(tc.arry[i]);
    }}
      

  3.   


    arr = new int[5];
    arr[0] = 1;
    arr = new int[]{1,2,3,4,5};