Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question
java intro. This code is alreay done. However, there should not be % at the end of terminal. How to remove it. Someone said add print(“\n”) at the end(parellel to loop). It works without % anymore. But there will be a new line when there is no argument when using ---java Filter odd--, there will be a new line. Thus, I need remove % and also when (java Filter odd, java Filter even), it produces nothing, even a new empty line. Please revise this code to fit this requirement and try on the terminal about normal cases and empty cases. Thanks.
O Filter.java
1
class Filter {
2
// Task 3: Filter
public static void main(String[] args) {
boolean printOdd = false;
for (int i = 0; i < args.length; i++) {
if (i == 0) {
if (args[i].equals("odd")) {
print0dd = true;
} else {
7
10
print0dd = false;
11
}
12
continue;
}
13
int x = Integer.parseInt(args [i]);
if (x % 2 == 0) {
if (!print0dd) {
System.out.print(x + " ");
}
} else {
if (print0dd) {
14
15
16
17
18
19
20
System.out.print(x + " ");
}
21
22
23
}
24
}
25
}
PROBLEMS
OUTPUT
DEBUG CONSOLE
TERMINAL
> zsh
songkunhao@songkunhaodeMacBook-Pro cse11-exam2-starter-main 2 % javac Filter.java
songkunhao@songkunhaodeMacBook-Pro cse11-exam2-starter-main 2 % java Filter odd 2 3 4
songkunhao@songkunhaodeMacBook-Pro cse11-exam2-starter-main 2 % java Filter even 2 3 45 8
2 8 %
songkunhao@songkunhaodeMacBook-Pro cse11-exam2-starter-main 2 % java Filter even
songkunhao@songkunhaodeMacBook-Pro cse11-exam2-starter-main 2 %
expand button
Transcribed Image Text:O Filter.java 1 class Filter { 2 // Task 3: Filter public static void main(String[] args) { boolean printOdd = false; for (int i = 0; i < args.length; i++) { if (i == 0) { if (args[i].equals("odd")) { print0dd = true; } else { 7 10 print0dd = false; 11 } 12 continue; } 13 int x = Integer.parseInt(args [i]); if (x % 2 == 0) { if (!print0dd) { System.out.print(x + " "); } } else { if (print0dd) { 14 15 16 17 18 19 20 System.out.print(x + " "); } 21 22 23 } 24 } 25 } PROBLEMS OUTPUT DEBUG CONSOLE TERMINAL > zsh songkunhao@songkunhaodeMacBook-Pro cse11-exam2-starter-main 2 % javac Filter.java songkunhao@songkunhaodeMacBook-Pro cse11-exam2-starter-main 2 % java Filter odd 2 3 4 songkunhao@songkunhaodeMacBook-Pro cse11-exam2-starter-main 2 % java Filter even 2 3 45 8 2 8 % songkunhao@songkunhaodeMacBook-Pro cse11-exam2-starter-main 2 % java Filter even songkunhao@songkunhaodeMacBook-Pro cse11-exam2-starter-main 2 %
Your task is to write a program in Filter.java will filter an array of integers based on a given
command option.
Your program will have to support 2 command options and have the described behavior:
even - prints out a list of all the even integers provided as argument
• odd - prints out a list of all odd integers provided as argument
Filter will always have either even or odd as the first argument and have either none or some integers
as command line arguments.
If there are zero integers provided as command line arguments, print nothing (not even a new line)
$ javac Filter.java
$ java Filter even -1 0 1 2 3 4 5
0 2 4
$ java Filter odd -1 0 1 2 3 4 5
-1 1 3 5
$ java Filter odd
$ java Filter even
$ java Filter even -2 -4 -6 -8
-2 -4 -6 -8
expand button
Transcribed Image Text:Your task is to write a program in Filter.java will filter an array of integers based on a given command option. Your program will have to support 2 command options and have the described behavior: even - prints out a list of all the even integers provided as argument • odd - prints out a list of all odd integers provided as argument Filter will always have either even or odd as the first argument and have either none or some integers as command line arguments. If there are zero integers provided as command line arguments, print nothing (not even a new line) $ javac Filter.java $ java Filter even -1 0 1 2 3 4 5 0 2 4 $ java Filter odd -1 0 1 2 3 4 5 -1 1 3 5 $ java Filter odd $ java Filter even $ java Filter even -2 -4 -6 -8 -2 -4 -6 -8
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY