Hang Electric OJ (Java version)--2006 to find odd product __java

Source: Internet
Author: User
finding the product of odd numbers Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 92452 accepted Submission (s): 56850


Problem Description gives you n integers, and asks for the product of all the odd numbers in them.
Input input data contains multiple test instances, one row for each test instance, the first number of each row is N, indicating that this group of data has n, followed by n integers, you can assume that each set of data must have at least one odd.
Output outputs all odd numbers in each group, output one row for the test instance.
Sample Input
3 1 2 3 4 2 3 4 5
Sample Output
3 15
Import Java.util.Scanner;

public class Main {public
	static void Main (string[] args) {
		Scanner Scanner = new Scanner (system.in);
		
		while (Scanner.hasnextint ()) {
			int n = scanner.nextint ();
			int arr[] = new Int[n];
			for (int i=0;i<n;i++) {
				Arr[i] = Scanner.nextint ();
			}
			
			int sum=1;
			for (int i=0;i<n;i++) {
				if (arr[i]%2!=0) {
					sum = sum * arr[i];
				}
			}
			
			SYSTEM.OUT.PRINTLN (sum);}}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.