Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 Exercise2{
//add code below this line
//add code above this line
public static void main(String args[]){
boolean x = Boolean.parseBoolean(args[0]);
ArrayList y = new ArrayList();
for (int i =1; i < args.length; i++){
y.add(Integer.parseInt(args[i]));
}
getOddsEvens(x, 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 & 13,22,8,31
COMPILE AND TEST WITH FALSE & 13,22,8,31
COMPILE AND TEST WITH TRUE & 1,2,3,4,5
COMPILE AND TEST WITH FALSE & 1,2,3,4,5
Thank you
The previous answer doesn't work for me. please check the hint given

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part 3 Lnai 8726

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448440, 978-3662448441

More Books

Students also viewed these Databases questions