关于main()函数的问题?

class ArrayUtil{
	private static int index;

	public static void Arry(int[]src,int[]dst){
		if(src==null||dst==null){
			return;
		}
		for(int index=0;index<src.length&&index<dst.length;index++);{
		dst[index]=src[index];	
	}
}
public static void printArray(int[]arr){
	for(int index=0;index<arr.length;index++){
		if(index==0){
			System.out.println("[");
		}else{
			System.out.println(",");
		}
		System.out.println(arr[index]);
	}
	System.out.println("]");
	}
public static void copyArray(int[] array1, int[] array2) {
	// TODO Auto-generated method stub
	
}
}
public class Application {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int array1[]={1,2,3,4,5,6};
		int array2[]=new int[6];
		ArrayUtil.copyArray(array1,array2);
		ArrayUtil.printArray(array2);
		

	}

}
关于上面的代码,程序是先从main()函数开始运行还是从开头运行?上方代码打印出的是全为0的数组,能使打印内容是别的吗?应该怎么修改?


街角疯
浏览 1157回答 1
1回答

Its_forever

先从mian函数运行。mian函数是程序的入口。 ArrayUtil.copyArray(array1,array2);  这句代码调用的copyArray方法里面没有方法体。也就没有输出语句,所以这一行代码没有任何输出内容。ArrayUtil.printArray(array2);这句代码调用的printArray方法,有方法体,但是你传入的是array2,也就是你new出来的那个数组,里面全是0.(空数组中的元素默认为0)。如果想输出其他内容,比如你定义的 int array1[]={1,2,3,4,5,6};。 public static void main(String[] args) {         // TODO Auto-generated method stub         int array1[]={1,2,3,4,5,6};         ArrayUtil.printArray(array1);     }
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java