Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Reversing an Array Write a program that prompts the user for an integer, then asks the user to enter that many values. Store these values

Reversing an Array

Write a program that prompts the user for an integer, then asks the user to enter that many values. Store these values in an array and print the array. Then reverse th e array elements so that the first elemen t becomes the last element, the second element becomes the second to last element, and so on, with the old last element now first. Do not just reverse the order in which they are printed; actually change the way they are stored in the array. Do not create a second array; just rearrange the elements within the arra y you have. (Hint: Swap elements that need to change places.) When th e elements have been reversed, print the array again

Averaging Numbers

As discussed in Section 7.4 of the text book, when you run a Java program called Foo, anything typed on the command line after java Foo is passed to the main method in the args parameter as an array of strings.

1. Write a program Average.java that just prints the strings that it is given at the command line, one per line. If nothing is given at the command line, print No arguments.

2. Modify your program so that it assumes the arguments given at the command line are integers. If there are no arguments, print a message. If there is at least one argument, compute and print the average of the arguments. Note that you will need to use the parseInt method of the Integer class to extract integer values from the strings that are passed in. If any non-integer values are passed in, your program will produce an error, which is unavoidable at this point.

3. Test your program thoroughly using different numbers of command line argument

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

Oracle 10g Database Administrator Implementation And Administration

Authors: Gavin Powell, Carol McCullough Dieter

2nd Edition

1418836656, 9781418836658

More Books

Students also viewed these Databases questions

Question

Focuses strongly on achievement and success in self and others.

Answered: 1 week ago