Write a program in Java to accept 10 numbers and count the frequency of consecutive even numbers in that array. Display the location of the even number with proper message.
Example:
{2,3, 4, 10, 6, 23,12,34,9,3}
Ans: 4, 10
10, 6
12, 34
Answers
Answered by
7
Answer:
import java.util.*;
public class Exercise92 {
public static void main(String[] args)
{
int[] nums = {5, 7, 2, 4, 9};
int ctr_even = 0, ctr_odd = 0;
System.out.println("Original Array: "+Arrays.toString(nums));
for(int i = 0; i < nums.length; i++) {
if(nums[i] % 2 == 0)
{
ctr_even++;
}
else
ctr_odd++;
}
System.out.printf("\nNumber of even elements in the array: %d",ctr_even);
System.out.printf("\nNumber of odd elements in the array: %d",ctr_odd);
System.out.printf("\n");
}
}
Explanation:
Hope this helps..
Similar questions
Math,
3 months ago
English,
3 months ago
English,
3 months ago
Psychology,
6 months ago
English,
6 months ago
Math,
10 months ago
Social Sciences,
10 months ago