java intro. Im almost done. just one small question. How to I remove % on the terminal. Also,if it can be removed,it also must ensure that the empty (java Filter odd)will not generate a new line. Maybe should add some statements to handle this,like if statement?

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
java intro. Im almost done. just one small question. How to I remove % on the terminal. Also,if it can be removed,it also must ensure that the empty (java Filter odd)will not generate a new line. Maybe should add some statements to handle this,like if statement?
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
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
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 %
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 %
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY