题目:包含如下初始数据:a1,a2,a3,a4,a5.已知另一字符串数组,包含如下初始数据:b1,b2,b3,b4,b5.编写程序将该两个数组的每一对应的数据相加存入另一个数组。输出结构为c1,c2,c3,c4,c5.
百度的基础题,思路简单,创建两个数组存储原始数据,在建一个数组来存相加后的数据。做循环将两个数组的元素按顺序相加放入另一个数组中并按顺序输出。
代码:
package shuzu;
public class jiafa {
public static void main(String args[]){
String a[]={"a1","a2","a3","a4","a5"};
String b[]={"b","b2","b3","b4","b5"};
String c[]={"","","","",""};
for(int i=0;i<a.length;i++){
c[i]=a[i]+"+"+b[i];
System.out.println(c[i]+",");
}
}
}
运行结果:
a1+b,
a2+b2,
a3+b3,
a4+b4,
a5+b5,
感觉好low啊!