Wednesday, January 16, 2008

[2D array]Sum of Even and Odd

WAP a program to find the product of all the even elements and all the odd elements present in the array

//Wap to Store 12 elements in a array of size 3X4 and find the sum of all the elements
//and product of even elements and odd elements.

import java.io.*;
class EvenOdd
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int a[][]=new int[3][4];
int s=0,even=1,odd=1;
System.out.println(" Enter 12 elements for array one :");
for(int i=0;i<3;i++)
{
for(int j=0;j<4;j++)
{
a[i][j]=Integer.parseInt(br.readLine());
s=s+a[i][j];
if(a[i][j]%2==0)
even=even*a[i][j];
else
odd=odd*a[i][j];
}
}
System.out.println(" Sum = " +s);
System.out.println(" Product of Even = " + even );
System.out.println(" Product of odd = " + odd);
}
}

No comments: