Computer Science, asked by write2sashadsilva, 1 month ago

Plz answer asap.
Read the above set of data and print average of odd and even numbers separately on the screen. Data: 7,3,5,6,2,9,22,4,55,68,22,11
Output : Average of odd numbers = 15 Average of even numbers = 20.67
I will be reporting false answers.

Answers

Answered by kumarijyotisp18
1

Answer:

public class findavg{

public static void main(String args[]){

int oddSum=0,evenSum=0,evenCount=0,oddCount=0;

int arr[]={7,3,5,6,2,9,22,4,55,68,22,11};

int i=0;

while(i<12){

if(arr[i]%2==0){

evenSum=evenSum+arr[i];

evenCount++;

}

else{

oddSum=oddSum+arr[i];

oddCount++;

}

i++;

}

double avgOdd=oddSum/oddCount;

double avgEven=evenSum/evenCount;

System.out.println("\nSum of even numbers are:"+avgEven);

System.out.println("\nSum of odd numbers are:"+avgOdd);

}

}

output :

Average of even numbers are:20.67

Average of odd numbers are:15

Similar questions