public int[] T(int x){
  int temp = 0;
  int num = 0;
  int array[] = null;
  temp = S(x);
  array[0] = temp;
  while(S(temp)!=x){
  temp = S(temp);
  num++ ;
  array[num]=temp;
  }
  array[num+1]=S(temp); 
  return array;
   }可行吗?需要改进什么地方。我对java的数组是在不熟悉,不知道到底该用什么?

解决方案 »

  1.   

    提一个观点。JAVA定义后会初始化。所以不必自己初始化。
    兄弟以前是用C++的吧。
      

  2.   

    基本数据类型的数组和Arrays配合着使用,里面有很强大的功能。
    至于对象对象数组,用ArrayList挺好的,JDK5.0已经支持泛型了,用起来很方便。
      

  3.   

    你的程序中数珠好象是可变的可以先用arraylist然后通过循环赋直以后在用相应的toarray方法转换成ARRAY即可
      

  4.   

       public ArrayList  T(int x){
      int temp = 0;
      int num = 0;
      ArrayList arraylist = new ArrayList();
      temp = S(x);
      arraylist.add(temp);
      while(S(temp)!=x){
      temp = S(temp);
      num++ ;
      arraylist.add(temp);
      }
      arraylist.add(S(temp)); 
      return arraylist;
       }这是我更改后的,但是有个问题,arraylist.add(temp);为什么会提示我
    Type safety: The method add(Object) belongs to the raw type ArrayList. 
     References to generic type ArrayList<E> should be parameterized
    而且arraylist.get(j);怎么将他转化为一个int类型的,为什么我object不是自动转化吗?
    我要实现取得的值和一个int比较,但是提示出错,例如arraylist.get(j) = 5。
      

  5.   

    arraylist.add(temp);//参数是Object对象 temp是int 你可以用Integer类
    arraylist.get(j) = 5
    //改为:((Integer)arraylist.get(j) ).doubleValue() == 5