36.0k views
1 vote
The purpose of this lab is to write a well commented java program that demonstrates the use of loops, logic for comparing doubles. Instructions 1. Write a Java program that asks the user for two integers, i1 and i2 (i2 > 11). 2. It then calculates and prints the sum of all odd numbers between i1 and i2 (inclusive) 3. It then prints sum of squares of all even numbers between 1 and 100. 4. After that it prompts the user to enter floating point values (or double values) until a sentinel value of Q (meaning quit) is entered. 5. It then prints the following: A. The average of the entered values B. The smallest and largest of entered values (you should not use == when comparing doubles and floats) C. After that the user is prompted for his/her first name. It prints the name in reverse. D. Important: Every number entered should be input validated. If your program crashes, you might get a 0. Sample Output ****LAB 4 Java Program Output Begin****** Enter the first integer: 23 Enter the second integer: 45 The sum of all odd numbers between 23 and 45: Sum of squares of all even numbers between 1 and 100: < Program should calculate this > Please enter some numbers: 1.0 34.0 15.0 25.0 21.0 1.0 The average of the entered values is: 16.66 The smallest number is: 1.0 The largest number is: 34.0 Please enter your first name: KEVIN Your name when reversed is: NIVEK **LAB 4 Java Program Output Ends**

1 Answer

5 votes

Final answer:

The student is asked to create a Java program that performs calculations involving loops and comparison of floating-point numbers, including summing odd numbers and squares, calculating averages, and finding the smallest and largest values, with input validation and string manipulation.

Step-by-step explanation:

The question pertains to writing a Java program that demonstrates the use of loops, conditional logic, and handling floating-point numbers without using the == operator for comparison. The program requires user input to perform specific operations such as summing odd numbers between two integers, summing squares of even numbers between 1 and 100, calculating the average, smallest, and largest values from a series of doubles, and reversing a user's first name.

To ensure accuracy and to avoid a program crash, input validation is emphasized. The output is to be formatted as shown in the example, with calculations for sums of odd numbers, sums of squares, averages, minimum and maximum values, and reversed first names all included within the program's results.

User Mardok
by
8.5k points