Objectives
- Use Java repetition statments to implement solutions to programmming problems
- Format output to match requirements
- Get user input from the command line
Note: Write a Java program for each of the programming projects listed below. The source code listings for these programs, and all others in this course, must include comments at the beginning of the source code which contain your name, the course, the date, and the assignment number. Submit your .java source files in Desire2Learn when you are done. It is considered cheating to copy work. Problems may be discussed, but not copied.
The processes of finding the largest number, smallest number, and adding up a series of numbers are used frequently in computer applications. Write a program that inputs an arbitrary series of numbers from the user. After each number the user enters display the smallest number, largest number, sum of the numbers, and average of the numbers so far. Have the program stop when the user enters the string "Quit" (whether it is lowercase or uppercase). Also display how many numbers have been entered after each number input.
Your program should have the following variables:
Hint: One way you can find the largest number is to assume the first number is the largest and save it in a variable named max. Then compare each number entered after that to max. If any number is greater than max, then max should be set equal to the new largest number.
Enter a number ('quit' to exit): -3 Count: 1, Minimum: -3.0, Maximum: -3.0, Sum: -3.0, Average: -3.0 Enter a number ('quit' to exit): 3 Count: 2, Minimum: -3.0, Maximum: 3.0, Sum: 0.0, Average: 0.0 Enter a number ('quit' to exit): 2 Count: 3, Minimum: -3.0, Maximum: 3.0, Sum: 2.0, Average: 0.7 Enter a number ('quit' to exit): 14 Count: 4, Minimum: -3.0, Maximum: 14.0, Sum: 16.0, Average: 4.0 Enter a number ('quit' to exit): -9 Count: 5, Minimum: -9.0, Maximum: 14.0, Sum: 7.0, Average: 1.4 Enter a number ('quit' to exit): 10 Count: 6, Minimum: -9.0, Maximum: 14.0, Sum: 17.0, Average: 2.8 Enter a number ('quit' to exit): quit
Write a Java application that asks the user for an integer from 2 through 15. If the number is out of range, display an error message and exit. Otherwise use a loop to display a right triangle with a height and base equal to the number the user entered. Use the "*" character to display the triangle. You should use nested loops to display the triangle. Any output statements you use for the triangle should print only a single "*" or a newline.
Enter an integer from 2 through 15: 1 Number out of range Enter an integer from 2 through 15: 16 Number out of range Enter an integer from 2 through 15: 10 * ** *** **** ***** ****** ******* ******** ********* ********** Enter an integer from 2 through 15: 5 * ** *** **** *****