Question: I am stuck with writing this code. I can only submit the question cause it does not let me submit another image to show my
I am stuck with writing this code. I can only submit the question cause it does not let me submit another image to show my code. Please assit. PRACTICE: Loops while: Compute modified average
Compute the average of a list of userentered integers representing rolls of two dice. The list ends when is entered. Integers must be in
the range to inclusive; integers outside the range don't contribute to the average. Output the average, and the number of valid and
invalid integers excluding the ending If only is entered, output The output may be a floatingpoint value. Ex: If the user enters
the output is:
Average:
Valid:
Invalid:
Hints:
Use a while loop with expression userInt
Read the user's input into userInt before the loop, and also at the end of the loop body.
In the loop body, use an ifelse to distinguish integers in the range and integers outside the range.
For integers in the range, keep track of the sum, and number of integers. For integers outside the range, just keep track of the number.
Use a cast to get a floatingpoint output: double sum num
Whenever dividing, be sure to handle the case of the denominator being
this is my code:
public class Main
public static void mainString args
Scanner scnr new ScannerSystemin;
int numValid;
int numInValid;
int userInt;
userInt scnrnextInt;
while userInt
if userInt && userInt
userInt userInt;
System.out.printlnAverage: userInt numValid;
userInt scnrnextInt;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
