Page 380 - CA_Blue( J )_Class10
P. 380
21 st
Some More Programs Century #Coding & Computational Thinking
Skills
To create a single-dimensional array of size 10. Accept 10 elements in the array and product of all
Program 1
the odd elements.
1 import java.util.*;
2 class array_product
3 { public static void main ()
4 { Scanner sc= new Scanner (System.in);
5 int ar[]=new int[10];
6 int i,p=1;
7 for (i=0; i<10; i++)
8 { System.out.print("Enter a number: ");
9 ar[i] =sc.nextInt();
10 if(ar[i]%2==1)
11 {
12 p=p*ar[i];
13 }
14 }
15 System.out.println("Product of Odd Numbers:"+p);
16 }
17 }
You will get the following output:
Enter a number: 1
Enter a number: 2
Enter a number: 3
Enter a number: 4
Enter a number: 5
Enter a number: 6
Enter a number: 7
Enter a number: 8
Enter a number: 9
Enter a number: 10
Product of Odd Numbers: 945
378378 Touchpad Computer Applications-X

