Question

write a java program that takes in 5 numbers and finds the average of the ones...

write a java program that takes in 5 numbers and finds the average of the ones that are even

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

public class Tester3 {

    public static void main(String[] args){

    //Scanner function to get the input from user

    Scanner scan = new Scanner(System.in);

    int[] list;

    list = new int[5];

    for (int i = 0; i<list.length; i++){

            //Getting the numbers from user and storing it to array

            System.out.print("Enter numbers of the list: ");

            list[i] = scan.nextInt();

    }

    int count =0, sum=0;

    for(int i=0; i<list.length; i++){

            //Taking average only if the number is even

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

                  sum = sum+list[i];

                  count++;

            }

    }

    System.out.println("Average of the Even numbers : "+sum/count);

    }

}

Output:

Add a comment
Know the answer?
Add Answer to:
write a java program that takes in 5 numbers and finds the average of the ones...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT