Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. (50pts) Write a Java program A1p2.java with a public class A1p2 and no named packages that takes one command line argument assumed to

 

2. (50pts) Write a Java program A1p2.java with a public class A1p2 and no named packages that takes one command line argument assumed to be a positive integer n. The program should prompt the user to input n integers from stdin (one per line) and store all of them in an array. After the program reads in the input integers, it should print the largest odd input integer and the smallest even input integer. You can assume that at least two integers will be input from stdin (ie, n>-2) and at least one even integer and at least one odd integer will be input from stdin. (Can you imagine how your program would function if no even integer or no odd integer is input from stdin?) You can consider designing additional method(s) besides main to implement the functionality. A sample run can look like the following (blue color means those are typed by the user; note that n can be any number and 5 is just an example): [kwang@computer/temp]$ java Alp2 5 2 -3 8 co in 5 12 The largest odd input integer is 5. The smallest even input integer is 2. If you run the program with standard input redirection, a sample run can look like the following (assuming the text file someNumbers2.txt contains the 2,3,8,5,12 on five separate lines): [kwang@computer/temp] $ java Alp2 5

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

Java Concepts Late Objects

Authors: Cay S. Horstmann

3rd Edition

1119186714, 978-1119186717

More Books

Students also viewed these Programming questions

Question

Using a graphing utility, graph y = cot -1 x.

Answered: 1 week ago

Question

Calculate SE ( p ) for n=100 and the values of p given 18. p=.30

Answered: 1 week ago

Question

Calculate SE ( p ) for n=100 and the values of p given 19. p=.50

Answered: 1 week ago