java技术博客

jsp博客
数据加载中……
ArrayTest.java
/**
*通过这个程序,我们要测试两个方面:
*1.匿名数组可以赋值与一个已经存在数组变量,不关心原来数组变量的容量
*2.数组变量的类型必须要与匿名数组的类型一致




public class ArrayTest{
public static void main(String[] args){
ArrayTest aTest=new ArrayTest();
int[] a={1,2,3};//声明一个新的数组,并赋值与一个新的数组变量
aTest.aprint(a);
a=new int[]{10,20,30,40,50};//将匿名数组赋值与存在的数组变量a
//a=new String[]{"a","b"};//将字符型匿名数组赋值与存在的数组变量a
aTest.print(a);
}
public void print(int[] array){
System.out.println(" 数组变量的长度是 "+array.length);
System.out.println(" 数组中的每一个元素是:");

for(int i=0;i<array.length;i++)
{
System.out.print(" "+array[i]);//打印出数组中的每一个元素
}System.out.println("\n*************");
}
}

posted on 2008-10-22 07:26 郭兴华 阅读(86) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: