Answer to Question #16587 in Java | JSP | JSF for Sayed Abdullah Almousawi

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.
1
Expert's answer
2012-10-16T11:41:12-0400
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);

}

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS