We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent bde055b commit 47385cfCopy full SHA for 47385cf
1 file changed
1st_November_exam_SET-2/JAVA_SET_2_Q3.java
@@ -0,0 +1,35 @@
1
+import java.util.Scanner;
2
+public class Question3{
3
+ public static void main(String[] args) {
4
+ Scanner input = new Scanner(System.in);
5
+ int s;
6
+ s = input.nextInt();//define size of array
7
+ //The array is defined "arr" and elements are of integer type.
8
+ int[] arr = new int[s];
9
+ for(int i=0;i<arr.length;i++)
10
+ {
11
+ arr[i]=input.nextInt();
12
+ }
13
+
14
15
16
+ //Find the average of all odd numbers present in that array and print the same.
17
+int j,sum=0,count=0;
18
+double avg=0;
19
+for(j=0;j<s;j++)
20
+{
21
+ if(arr[j]%2!=0)
22
23
+ count++;
24
+ sum+=arr[j];
25
26
+}
27
+avg=(double)sum/count;
28
+if(count==0)
29
30
+ avg=0;
31
+System.out.print(avg);
32
+}else
33
34
35
0 commit comments