杭电acm P2006

来源:互联网 发布:淘宝客卖家推广教程 编辑:程序博客网 时间:2024/06/16 16:11

Problem Description
给你n个整数,求他们中所有奇数的乘积。

Input
输入数据包含多个测试实例,每个测试实例占一行,每行的第一个数为n,表示本组数据一共有n个,接着是n个整数,你可以假设每组数据必定至少存在一个奇数。

Output
输出每组数中的所有奇数的乘积,对于测试实例,输出一行。

Sample Input
3 1 2 3
4 2 3 4 5

Sample Output
3
15

import java.util.Scanner;public class P2006 {    public static void main(String[] args) {         Scanner sc=new Scanner(System.in);          while(sc.hasNext()){          int n=sc.nextInt();         int[] a=new int[n];         int mul=1;         for(int i=0;i<a.length;i++){          a[i]=sc.nextInt();          if(a[i]%2!=0){             mul=a[i]*mul;           }         }         System.out.println(mul);         }    }  }
原创粉丝点击