Question

Add an improved version of the the func4on called od2ev that returns true if the number...

Add an improved version of the the func4on called

od2ev

that returns

true

if the

number of odd numbers is twice more than the number of even numbers

Function:

bool ev5(int a1[], int l1) {

int evenCount = 0;

for(int i=0;i<l1;i++) {

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

evenCount++;

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


public class abcexamp {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int arr[]={2,12,31,11,99,87};
boolean b=od2ev(arr);
System.out.println("odd numbers is twice greater:"+b);
}
public static boolean od2ev(int arr[]){
int oddcount=0;
int evencount=0;
for(int i=0;i<arr.length;i++){
if(arr[i]%2==0)
evencount++;
else
oddcount++;
}
//System.out.println(evencount+" "+oddcount);
if(evencount*evencount==oddcount)
return true;
else
return false;
}
}

output:
odd numbers is twice greater:true
screenshots:

//as you dint mention any specific programing language ..i implemented in java...executed code is provided..and //also screenshots are provided...thank you

Add a comment
Know the answer?
Add Answer to:
Add an improved version of the the func4on called od2ev that returns true if the number...
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
  • Write a method that takes an array of ints and that returns true if there are...

    Write a method that takes an array of ints and that returns true if there are more odd numbers than even numbers. However, as for a casino, 0 is not counted as an odd or an even number. If the array is empty or contains only 0's the method should return false.

  • C++ question. Please help, thank you! Write a function called averageOdd that returns the average of...

    C++ question. Please help, thank you! Write a function called averageOdd that returns the average of all of the odd numbers in a 2-Dimensional array with 3 columns. If no odd numbers are present, it should return a result of 0. Excessively long solutions that use more than 15 lines of code may lose points. For example, a program that uses the function averageOdd follows: int main() { int data[2][3] = {{3, 1, 4} , {2, 7, 1}}; cout <<...

  • In class Recursion problems bool anyNegative(int al , int size) This function returns true if there...

    In class Recursion problems bool anyNegative(int al , int size) This function returns true if there are any negative numbers in the array, grity false otherwise. int firstNegative(int al I, int size) This function returns the position of the first negative number in the array & EAO If there are no negative numbers it returns int countNegative(int al I, int size) This function returns the number of negative numbers in the array a. 12 bst Stringsint indexO bout Strings nt...

  • Subject: C++ I have created a class called QueueOfIntegers in a file called QueueOfIntegers.h, which is...

    Subject: C++ I have created a class called QueueOfIntegers in a file called QueueOfIntegers.h, which is here: #ifndef QueueOfIntegers_H #define QueueOfIntegers_H class QueueOfIntegers { public:    int elements[100]; //Array to store integers in the queue    int size; // Number of integers in the queue    QueueOfIntegers(); // Construct an empty queue    bool IsEmpty(); // Returns true if the queue is empty    int Peek(); // Returns the integer at the beginning of the Queue without removing it   ...

  • Programming language C Please go through this carefully. Needs function void add(int *a1, int n, int...

    Programming language C Please go through this carefully. Needs function void add(int *a1, int n, int *a2) Write a program addition.c that reads in an array (a1) of numbers, and creates a new array (a2) of numbers such that the first and last numbers of a1 are added and stored as the first number, the second and second-to-last numbers are added and stored as the second number, and so on. You need to check for even and odd length of...

  • Write a function that takes an int as an argument and returns true if the int...

    Write a function that takes an int as an argument and returns true if the int is an even number and false if not. In any case change the value of the original argument to twice its value. Use the integers 0 through 4 as test cases. Do not use any arrays.

  • using c++ Write a function that returns true if a given integer array is sorted(in ascending...

    using c++ Write a function that returns true if a given integer array is sorted(in ascending order) and false if it is not. The function should perform no more than "size" comparisons. bool isSorted(int A[], int size);

  • Credit card numbers follow certain patterns. A credit card number must have between 13 and 16...

    Credit card numbers follow certain patterns. A credit card number must have between 13 and 16 digits. The number must start with the following: 4 for Visa cards 5 for MasterCard cards 37 for American Express cards 6 for Discover cards In 1954, Hans Luhn of IBM proposed an algorithm for validating credit card numbers. The algorithm is useful to determine whether a card number is entered correctly or is scanned correctly by a scanner. Almost all credit card numbers...

  • Add a function int countPrimes(int a, int b); that returns the number of prime numbers in...

    Add a function int countPrimes(int a, int b); that returns the number of prime numbers in the interval a ≤ x ≤ b. Change the main function to test the new code. Please, it needs to be a function above/before the main function and it is necessary to use the given names. Thanks

  • Can some help me with my code I'm not sure why its not working. Thanks In...

    Can some help me with my code I'm not sure why its not working. Thanks In this exercise, you are to modify the Classify Numbers programming example in this chapter. As written, the program inputs the data from the standard input device (keyboard) and outputs the results on the standard output device (screen). The program can process only 20 numbers. Rewrite the program to incorporate the following requirements: a. Data to the program is input from a file of an...

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
ADVERTISEMENT