‫Hello my friends, and welcome to coding Exercise number seven.
‫In this exercise, we are asked to write a Java program to count the number of even and odd elements
‫in a given array of integers.
‫For example, we have 57249 that these are the elements inside this brain.
‫We need to count the odd elements and the event elements, odd elements, five, seven, nine and the
‫even elements do for.
‫So it will display for us, the program will display number of even elements is two.
‫The number of odd elements is three.
‫Post the video and think about how to solve such a problem and such as an exercise.
‫And by the way, I am waiting your solutions.
‫Please write down in the comments below your solution in order to help you understanding what your problem
‫is or where is the the missing things that we can advise you to concentrate and we teach and help you
‫in order to solve these exercises.
‫And welcome again.
‫I hope you solve it well.
‫I will start creating the array that we need to check for the even an odd elements.
‫This is the array
‫57249
‫and I will start by even and even counter equal to zero and end odd.
‫The counter is equal to zero.
‫So.
‫I will start the checking for loop.
‫I told you, when?
‫Whenever you deal with addres, you need to think about using the for loops and the loops in general
‫I equal to zero.
‫I will be going until nums that length is reached.
‫I plus plus if the numbers at index I modulo two modulo two as the key to check for even and or this
‫modulo modulo to check is used to check for parity.
‫So if it is.
‫Module two.
‫The remainder will equal equal to zero.
‫Then there is not a remainder.
‫So it will be an even, for example, ten modulo two it will give me zero because the division will
‫result in five and no remainder is remained.
‫So there then is an even I need to add to increase the even counter by one else.
‫I will increase the odd counter by one.
‫Then I need to display after for loop.
‫I need to display that as system that output print l n the number of event numbers.
‫And here I need to print odd numbers.
‫And here I will display the counter of even And here I will display the odd counter.
‫Okay.
‫Let me run with the coverage here.
‫And here we go.
‫In our example, the number of even numbers are two, two and four, and the number of odd numbers is
‫three, five, seven and nine.
‫So congratulations, guys.
‫I hope you solve it well and solve it like me.
‫Please, if you have any question or any doubt, we need we need us to you need us to help you, please
‫write it down in your comment in the comments below and please support us by rating our course.
‫Five stars on Udemy to make more and more exercises and help many people.