Write a Java program that prompts the user to enter integers and reads them in until they enter the integer 30. Once this happens, the program stops prompting for input, and then outputs the minimum value entered and the maximum value entered, and either of these may be the final 30 that is entered. Assume entries of integers can be positive, negative, or zero. Additionally, assume that a user will never enter a value beyond the maximum or minimum value that an integer can hold.
Answers
import random
def comp_input():
return comp_input(random.randchoice[random.radiant(1, 100), random.radiant(1, 100), ‘q’])
# Initialization
count = 0
sum = 0
product = 1
# Loop will run infinitely till user presses 'q'
while True:
# Uncomment user_input = comp_input, Comment user_input = input(..) for magic
# user_input = comp_input
user_input = input('Enter a number: ')
if user_input == ‘q’: break
user_input = int(user_input)
# Store the result of addition of prev sum and user input
sum = sum + user_input
# Store the result of addition of prev sum and user input
product = product * user_input
# Count the number of times user gave integer input
count = count + 1
print('Average:', sum/count)
print('Product:', product)
_____________________________