统计信息

  • 访问数:9422
  • 博客数:142
  • 建立时间:2008-01-05
  • 更新时间:2008-05-21
我叫王超然,是一名电脑爱好者,现在在新加坡留学上高一.我立志成为一名电脑人才,愿意在这里与大家一同分享我玩转电脑的心得.O-level华文考了A-One哈哈!

P6Q13

2008-04-15 13:49:23

天气: 晴朗 心情: 高兴

/*filename:P6Q13
 *Name:Wang Chaoran
Desciprtion:
13 (Increasing array size)
Once an array is created, its size is fixed. Occasionally,
you need to add more values to an array, but it is full.
In such cases, you can create a new, larger array to replace the existing array.
Write a method with the following header:
public static int[] doubleCapacity(int[] list)
The method returns a new array that doubles the size of the parameter list.
*/
class P6Q13{
  public static void main(String[] args){
    int[] test = {0,1,2,3,4,5,6,7,8,9};
    int[] array = doubleCapacity(test);
    System.out.println("The length of the new array: "+array.length);
    for(int i=0;i<array.length;i++){
    System.out.print(array[i]+" ");
    }
   
  }
  public static int[] doubleCapacity(int[] list){
  int[] array = new int[list.length*2];
  for(int i = 0;i<list.length;i++)
    array[i]=list[i];
  return array;
  }
 
}
加入收藏 编辑 审核

TAG: computing

我来说两句

OPEN

Powered by X-Space 1.2 © 2001-2006 Comsenz Technology Ltd