[Java] 纯文本查看 复制代码 package luntan;
/*
* 一.需求:
* (1)定义一个int类型的一维数组,内容为{171,72,19,16,118,51,210,7,18}
* (2)求出该数组中满足要求的元素和。
* 要求:求元素的个位和十位不能包含7,并且只能为偶数。
* */
public class Tsest_Array {
public static void main(String[] args) {
int [] arr = {171,72,19,16,118,51,210,7,18};
int ge;
int shi;
int sum = 0;
for (int i = 0; i < arr.length; i++) {
if (arr[i] > 10) {
ge = arr[i] % 10;
shi = (arr[i] - ge ) / 10 % 10;
if(ge % 2 == 0 && ge != 7 && shi != 7 ) {
sum += arr[i];
}else {
}
}else {
ge = arr [i];
if(ge % 2 == 0 && ge != 7 ) {
sum += arr[i];
}
}
}
System.out.println(sum);
}
}
|