[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
1.本题目要求得的两个向量的和,每一个向量通过一个一维数组表示,具体要求为:
1在Main类中.创建一个方法,方法功能为求两个一维数组之和得到求和数组并返回。方法声明为:
public static int[] add(int arr[],int []arr2)
2.在main方法中创建两个一维数组,一维数组的长度通过键盘得到,数组的元素通过键盘输入。
3.调用add方法得到两个一维数组之和,并输出这个一维数组的值。
输入格式:
第一行输入数组的元素个数
第二行输入第一个数组的各个元素 中间以空格隔开
第三行输入第二个数组的各个元素 中间以空格隔开
输出格式:
输出求和数组的各个元素,每行输出一个元素。
输入样例:
在这里给出一组输入。例如:
4 1 2 3 4 5 6 7 8
输出样例:
在这里给出相应的输出。例如:
6 8 10 12
参考答案:
import java.util.Scanner; public class Main { public static void main(String[]
args) { Scanner sc = new Scanner (System.in); int n = sc.nextInt(); int [] a1 =
new int[n]; int [] a2 = new int[n]; for(int i=0;i<n;i++) { a1[i] =
sc.nextInt(); } for(int i=0;i<n;i++) { a2[i] = sc.nextInt(); } for(int
i=0;i<n;i++) { int sum = a1[i]+a2[i]; System.out.println(sum); } sc.close(); } }