July 04, 2013

Java program to find Product of Odd and Even Number

Write a Java program that displays the PRODUCT of ODD and  EVEN Number.


PRODUCT(ODD  EVEN)


import java.io.*;
class prod
{
public static void main(String[] ar)
{
int num[]=new int[10];
int num_e[]=new int[10];
int num_o[]=new int[10];
int n,prod_e=1,prod_o=1;
int a=0,b=0,i;
DataInputStream in=new DataInputStream(System.in);
try{
System.out.println("Enter the total number of input:");
n=Integer.parseInt(in.readLine());
System.out.println("Enter the "+n+" numbers:");
for(i=1;i<=n;i++)
{
num[i]=Integer.parseInt(in.readLine());
}
for(i=1;i<=n;i++)
{
if(num[i]%2==0)
{
num_e[a]=num[i];
a++;
}
else{
num_o[b]=num[i];
b++;
}
}
System.out.println("THe product of even numbers=");
for(i=0;i<a;i++)
{
if(a==0)
{
System.out.println("No even numbers");
break;
}
prod_e*=num_e[i];
}
System.out.println(""+prod_e);
System.out.println("THe product of odd numbers=");
for(i=0;i<b;i++)
{
if(b==0)
{
System.out.println("No odd numbers");
break;
}
prod_o*=num_o[i];
}
System.out.println(""+prod_o);
}
catch(Exception yy){}
}
}



OUTPUT

C:\Program Files\Java\jdk1.5.0\bin>java prod
Enter the total number of input:
5
Enter the 5 numbers:
1
3
5
6
7
THe product of even numbers=
6
THe product of odd numbers=
105

No comments:
Write comments