Question #16587

Write a Java program that reads from the user an integer N followed by N integers. The program then prints the product of odd integers, and, the sum of even integers.

Expert's answer

import java.util.Scanner;

public class main

{

public static

void main(String[] args)

{

Scanner sc = new

Scanner(System.in);

System.out.println("Enter number of

integers");

int N = sc.nextInt();

int[] arr=new

int[N];

System.out.println("Enter "+N+" numbers");

for (int i = 0; i

< arr.length; i++)

{

arr[i]=sc.nextInt();

}

int

prodOfOddInt=1;

int SummOfEvenInt=0;

for (int i = 0; i < arr.length;

i++)

{

if(arr[i]%2==1)

{

prodOfOddInt*=arr[i];

}

else

{

SummOfEvenInt+=arr[i];

}

}

System.out.println("the

product of odd integers: "+prodOfOddInt);

System.out.println("the sum of even

integers: "+SummOfEvenInt);

}

}

public class main

{

public static

void main(String[] args)

{

Scanner sc = new

Scanner(System.in);

System.out.println("Enter number of

integers");

int N = sc.nextInt();

int[] arr=new

int[N];

System.out.println("Enter "+N+" numbers");

for (int i = 0; i

< arr.length; i++)

{

arr[i]=sc.nextInt();

}

int

prodOfOddInt=1;

int SummOfEvenInt=0;

for (int i = 0; i < arr.length;

i++)

{

if(arr[i]%2==1)

{

prodOfOddInt*=arr[i];

}

else

{

SummOfEvenInt+=arr[i];

}

}

System.out.println("the

product of odd integers: "+prodOfOddInt);

System.out.println("the sum of even

integers: "+SummOfEvenInt);

}

}

## Comments

## Leave a comment