InterviewSolution
| 1. |
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 |
|
Answer» 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. = 2SOLUTION:-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);}} |
|