Skip to content

Commit 47385cf

Browse files
authored
Add files via upload
1 parent bde055b commit 47385cf

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
System.out.print(avg);
34+
}
35+
}

0 commit comments

Comments
 (0)