-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEvenProd.java
More file actions
48 lines (40 loc) · 1.01 KB
/
Copy pathEvenProd.java
File metadata and controls
48 lines (40 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package Practice;
//Write a Java program to print the product of even numbers only
//
// Example:
//
// input1: 5
//
// input2: 9 12 1 19 22
//
// output: 2 4
import java.util.Scanner;
public class EvenProd {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int arr[]=new int[n];
int num;
int rem;
int even_count=0;
for(int i=0;i<arr.length;i++){
arr[i]=sc.nextInt();
}
for(int i=0;i<arr.length;i++){
num=arr[i];
int prod=1;
if(arr[i]%2==0){
even_count++;
while(num>0){
rem=num%10;
prod*=rem;
num=num/10;
}
System.out.print(prod+" ");
}
}
if(even_count==0){
System.out.println("No Even Numbers");
}
}
}