求奇数和。输入一个正整数repeat(0<repeat<10),做repeat次下列运算:读入一批正整数(以零或负数为结束标志),求其中奇数和。

 

代码:

 1 import java.util.*;
 2 public class Main {
 3     public static void main (String [] args) {
 4         Scanner s=new Scanner(System.in);
 5         int repeat,x;
 6         repeat=s.nextInt();
 7         for(int i=1;i<=repeat;i++) {
 8             x=s.nextInt();
 9             int sum=0;
10             while(x>0) {
11                 if(x%2!=0) {
12                     sum+=x;                
13                 }
14                 x=s.nextInt();
15             }
16             System.out.println(sum);
17         }
18     }
19 }

 

posted @ 2019-06-17 17:09  DehuiFan  阅读(3303)  评论(0编辑  收藏  举报