Question: Write a method called getOddsEvens ( ) that takes a boolean and an Integer ArrayList as parameters. If the boolean parameter is true, print only
Write a method called getOddsEvens that takes a boolean and an Integer ArrayList as parameters. If the boolean parameter is true, print only the even integers separated by a newline. If the boolean parameter is false, print only the odd integers separated by a newline.
Existing code
Existing Code:
import java.util.;
public class Exercise
add code below this line
add code above this line
public static void mainString args
boolean x Boolean.parseBooleanargs;
ArrayList y new ArrayList;
for int i ; i args.length; i
yaddIntegerparseIntargsi;
getOddsEvensx y;
Don't change the existing code use it
Hint
The main method's job is to take the first command and turn it into a boolean x Then take the second command and every command after and turn those into integers. These integers are then added to an ArrayList y Your task is to check whether the boolean is true or false and print only the relevant integers within the ArrayList that correspond to true or false.
Compile and test your code with a few different values
COMPILE AND TEST WITH TRUE &
COMPILE AND TEST WITH FALSE &
COMPILE AND TEST WITH TRUE &
COMPILE AND TEST WITH FALSE &
Thank you
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
