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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started