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. 6.4 PRACTICE: Loops (while)**: Compute modified average
Compute the average of a list of user-entered integers representing rolls of two dice. The list ends when 0 is entered. Integers must be in
the range 2 to 12(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 0). If only 0 is entered, output 0. The output may be a floating-point value. Ex: If the user enters 812
130, the output is:
Average: 10
Valid: 2
Invalid: 1
Hints:
Use a while loop with expression (userInt !=0).
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 if-else 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 floating-point output: (double) sum / num .
Whenever dividing, be sure to handle the case of the denominator being 0.
this is my code:
public class Main {
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
int numValid;
int numInValid;
int userInt;
userInt = scnr.nextInt();
while (userInt !=0){
if (userInt >=2 && userInt =12){
userInt = userInt++;
System.out.println("Average: "+(userInt / numValid));
}
userInt = scnr.nextInt();
 I am stuck with writing this code. I can only submit

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!