Welcome to Westonci.ca, the place where your questions are answered by a community of knowledgeable contributors. Discover a wealth of knowledge from experts across different disciplines on our comprehensive Q&A platform. Experience the ease of finding precise answers to your questions from a knowledgeable community of experts.

Design and implement a program that reads a series of 10 integers from the user and prints their average. Read each input value as a string, and then attempt to convert it to an integer using the Integer.parseInt method. If this process throws a NumberFormatException (meaning that the input is not a valid number), print an appropriate error message and prompt for the number again. Continue reading values until 10 invalid integers have been entered.

Sagot :

Answer:

Explanation:

The following program was written in Java. It creates a loop that asks the user for numbers. If it can convert it to an integer it accepts it and adds it to the sum variable otherwise it ouputs that it is not a valid number. Once all 10 integers are added it prints the Average of the values entered.

import java.util.ArrayList;

import java.util.Scanner;

class Brainly {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       int count = 0;

       int sum = 0;

       while (count != 10) {

           System.out.println("Enter a number: ");

           String answer = in.nextLine();

           try {

               int intAnswer = Integer.parseInt(answer);

               sum += intAnswer;

               count += 1;

           } catch (NumberFormatException e) {

               System.out.println("Not a valid number.");

           }

       }

       int average = sum / count;

       System.out.println("Average: " + average);

   }

}

View image sandlee09