⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arraycopy.java

📁 贪食蛇的实现源码
💻 JAVA
字号:
package array;

/*拷贝数组:int myArray[] = { 1, 2, 3, 4, 5, 6 }; 

目标数组:int hold[] = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }; 
使用方法System.arraycopy();参数解释(要拷贝的数组,开始位置
开始位置,拷贝长度),最后打印出目标数组中所有的元素,数组和自定义方法实现*/
public class Arraycopy {

	
	public static void main(String[] args) {
		int myArray[] = {1,2,3,4,5,6};
		int [] sixs = new  int[6];
		String [] ss= new String[6];
		System.out.print(ss[5]+"大小"+sixs.length);
		int[] myArray1={0,0,0,0,0,0}; //定义数组int[] myArray;
		//int[] hold=new hold[10];不用new 开辟空间
		//int array[10]={};不对
		int hold[]={10,9,8,7,0,0,0,0,0,0};//数组赋值就开辟空间了
		for(int i=0;i<myArray.length;i++)
			myArray1[i]=myArray[myArray.length-1-i];
		//System.out.println(myArray.length);
		System.arraycopy(myArray1,0,hold,4,myArray.length);//(myArray[0]不是位置是对应位置的数,0代表从数组零位置开始)
		System.out.print("{");
		for( int i=0;i<hold.length-1;i++)
			//System.out.print(hold[i]+"\t");//  "/t"原样输出;"\n"才输出换行
		System.out.print(hold[i]+",");
		System.out.print(hold[hold.length-1]+"}");
	}
			

}









⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -