编写Java程序,创建数组a和b,将数组a中索引位置0~3的元素复制到数组b中,最后将a和b数组中元素输出。求解
展开全部
String[] a = {"a","b","c","d","e"};
String[] b = {"1","2","3","4","5"};
System.arraycopy(a, 0, b, 0,3);
for (int i = 0; i < a.length; i++) {
System.out.print(a[i]);
}
System.out.println();
for (int i = 0; i < b.length; i++) {
System.out.print(b[i]);
}
String[] b = {"1","2","3","4","5"};
System.arraycopy(a, 0, b, 0,3);
for (int i = 0; i < a.length; i++) {
System.out.print(a[i]);
}
System.out.println();
for (int i = 0; i < b.length; i++) {
System.out.print(b[i]);
}
展开全部
import java.util.Arrays;
public class Test{
public static void main(String[] args) {
int[] a= {35, 22, 18, 36};
int[] b = {1, 3, 5, 122};
System.out.println("Before copied, array a: " + Arrays.toString(a));
System.out.println("Before copied, array b: " + Arrays.toString(b));
b[0] = a[0];
b[1] = a[1];
b[2] = a[2];
b[3] = a[3];
System.out.println("After copied, array a: " + Arrays.toString(a));
System.out.println("After copied, array b: " + Arrays.toString(b));
}
}
public class Test{
public static void main(String[] args) {
int[] a= {35, 22, 18, 36};
int[] b = {1, 3, 5, 122};
System.out.println("Before copied, array a: " + Arrays.toString(a));
System.out.println("Before copied, array b: " + Arrays.toString(b));
b[0] = a[0];
b[1] = a[1];
b[2] = a[2];
b[3] = a[3];
System.out.println("After copied, array a: " + Arrays.toString(a));
System.out.println("After copied, array b: " + Arrays.toString(b));
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
B数组是空的?如果不是,楼上正解
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询