本期作业:
//设计一个复制和打印一维数组的工具类
class ArrayUtil{
//数组复制方法
public static void copyArray(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 class Class2_text {
public static void main(String[] args) {
int array1[] = {2,3,4,5,6,9};
int array2[] = new int[6];
ArrayUtil.copyArray(array1,array2);
ArrayUtil.printArray(array2);
}
}
版权属于:乐心湖's Blog
本文链接:https://xn2001.com/archives/106.html
声明:博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!
2 comments
推荐系统的学习java core之后,看看设计模式和数据结构算法,排序算法就可以了
java输出的时候,最好不要多次打印,定义一个字符串,把要输出的信息,拼接到字符串中,最后再打印控制台。