我想从偶数中找到缺失的数字
例如:{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));
}
}
素胚勾勒不出你
慕慕森
慕田峪7331174
MYYA
海绵宝宝撒
莫回无
相关分类