Write a program in JAVAto input any 10 numbers in S.D.A. and find the average of odd numbers. [4] Example Input a[ ] = {4, 5, 9, 10, 12, 14, 16, 6, 22, 24} Output even no. = 8 and odd no. = 2
Answers
Answered by
5
Correct Question:-
Write a program in JAVAto input any 10 numbers in S.D.A. and find the average of even and odd numbers. Example:-
Input: a[ ] = {4, 5, 9, 10, 12, 14, 16, 6, 22, 24}
Output: even no. = 8 and odd no. = 2
Solution:-
import java.util.*;
class abc{
public static void main(String ar []){
Scanner sc=new Scanner (System.in);
int a[]=new int[10];
System.out.println("Enter 10 numbers");
for(int I=0;I<10;I++)
a[I]=sc.nextInt();
int s=0,s1=0,c=0,c1=0;
for(int I=0;I<10;I++){
if(a[I]%2==0){
s+=a[I];
c++;
}
else{
s1+=a[I];
c1++;
}
}
double avg=s/c;
double avg2=s1/c1;
System.out.println("even no.="+avg);
System.out.println("odd no.="+avg2);
}
}
Attachments:
Similar questions
Math,
29 days ago
Computer Science,
29 days ago
English,
29 days ago
Social Sciences,
1 month ago
Social Sciences,
1 month ago
Chemistry,
9 months ago
English,
9 months ago