You are on page 1of 1

More Array-For-While Loop Exercises.

Write programs as follows: 1. Write a while loop that uses a Scanner to ask a user for a list of positive decimal numbers terminated by -1 (which is not included in the list). The loop puts the numbers into an array of doubles called dArray. The program then uses a single for loop to calculate the following: a. The largest number in the list b. The smallest number in the list c. The average of the numbers Finally the program prints out the largest, smallest and average, with explanatory text: There are N numbers, the largest is 99999, the smallest is 00000, the average is 99999

2. Write a while loop that uses a Scanner to ask a user for a list of words terminated by XXX (which is not included in the list). The loop puts the words into an array of Strings called sArray. The program then uses a single for loop to print out the the words, separated by spaces, on a single line.

3. CHALLENGE Write a program that contains the following declaration: double iArray [] = {2.75, -4.8, 13, -21, 66.4, -9, 0, 1, -3.333,2,5,-99}; The program then creates a new array of the same size which contains the same numbers but sorted from smallest to largest, and prints it out.

You might also like