gpt4 book ai didi

java - 如何从偶数 {2,4,6,8,10,14} 中找到缺失的数字

转载 作者:行者123 更新时间:2023-11-29 10:08:29 25 4
gpt4 key购买 nike

<分区>

我想从偶数中找到缺失的数字

例如:{2,4,6,8,10,14};//输出应该是12

我试过:

public class MissingNumber {
public static void main(String[] args) {

int a[] = {2,4,6,8,10,14};
int sum = 0;
for (int i = 0; i<a.length; i++) {
sum = sum + a[i];
}


int sum1 = 0;
for(int j=1; j<=7; j++) {
sum1 = sum1 + j;
}
System.out.println("missing number is:"+(sum1-sum));
}
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com