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

2. (50pts) Write a Java program A2p2.java with a public class A2p2 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 these integers in original order and reverse all triplets in the array and then print all the array elements in this adjusted order. If n is not a multiple of 3, then the final one or two integers in the array should be kept intact. (Problem 20 in Prerequisite_Programming_Assignments is similar to this one and you may review that first.) Two sample runs can look like the following (blue color means those are typed by the user):

[kwang@computer][~/temp]$ java A2p2

5

2

-3

8

5

12

The original integers are: 2,-3,8,5,12

The triplets reversed integers are: 8,-3,2,5,12

[kwang@computer][~/temp]$ java A2p2

6

2

-3

8

5

12

7

The original integers are: 2,-3,8,5,12,7

The triplets reversed integers are: 8,-3,2,7,12,5

If you run the program with standard input redirection, a sample run can look like the following (assuming the text file someNumbers.txt contains the 2,-3,8,5,12 on five separate lines):

[kwang@computer][~/temp]$ java A2p2 5 < someNumbers.txt

The original integers are: 2,-3,8,5,12

The triplets reversed integers are: 8,-3,2,5,12

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!