1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
marin [14]
4 years ago
7

Write code that prompts for three integers, averages them, and prints the average. Make your code robust against invalid input;

if the user types a non-number, re-prompt with the same prompt message. (You may want to look at the getInt method discussed in Chapter 5. You can call that method in your solution if you like.) Here is an example dialogue: Type an integer: 5 Type an integer: 2 Type an integer: 17 Average: 8.0
Computers and Technology
1 answer:
MArishka [77]4 years ago
6 0

Answer:

The program to this question can be given as:

Program:

import java.util.*;  //import package for user input.

public class Main  //define class-main

{

   public static void main (String ar [])  //define main function

   {

       try  //try block

       {

           int a,b,c,sum=0;  //declare variable

           double average;

           Scanner ob= new Scanner(System.in);  //create Scanner class Object

           System.out.print("Enter first number :");  //message.

           a = ob.nextInt();  //input number.

           System.out.print("Enter second number :");

           b = ob.nextInt();

           System.out.print("Enter third number :");

           c = ob.nextInt();

           //print numbers

           System.out.print("\nFirst number:"+a);

           System.out.print("\nSecondnumber:"+b);

           System.out.print("\nThird number:"+c);

           sum =sum+a+b+c;    //Sum

           average = sum/3;  //Average

           System.out.print("\nAverage:" + average);  //print average

       }  

       catch (Exception e) //catch block.

       {

          System.out.print("Enter number only..!");  //message

       }

   }

}

Output:

Enter first number 5

Enter second number 2

Enter third number 17

First number: 5  

Second number: 2  

Third number: 17  

Average: 8.0

Explanation:

In the above program firstly we import packages for user input. Then we declare the main class. In the main class, we define the main function in the main function we use the exception handling. In the exception handling, we use try and catch block. In the try block firstly we declare variables then create a scanner class object and take input from the user. After user input we add all numbers into the sum variable then we take average in the average variable and print all values. If the user doesn't input a number then we use the catch block in this block it prints a simple message that is "Enter number only..!"

You might be interested in
How computer viruses spread from one computer to another​
morpeh [17]
Viruses spread when the software or documents they get attached to are transferred from one computer to another using a network, a disk, file sharing methods, or through infected e-mail attachments. Some viruses use different stealth strategies to avoid their detection from anti-virus software.
8 0
3 years ago
_______ and _____ are two major techniques involved in green computing. NextReset
FrozenT [24]
Green computing is the use of computers and related resources which is environmentally responsible. Energy-efficiency and e-waste are two major techniques involved in green computing. Energy efficiency involves implementation of energy-efficient central processing units (CPUs), servers and peripherals as well as reduced resource consumption. And e-waste is the proper disposal of electronic waste.


3 0
3 years ago
Read 2 more answers
Requests to retrieve data written in a language such as SQL are called…
Oksanka [162]
B. Queries

Queries can be fairly broad or written to focus on time frames, types of data, ranges etc.
5 0
3 years ago
Discuss Hashing and how it is utilized within the IT industry. Also, discuss how Hashing can improve our sorting and searching r
shusha [124]

Answer:

Hashing can be termed as the alteration of a string of characters into a frequently smaller fixed-length value or key that represents the original string.

Explanation:

Hashing are utilized to catalog and recover digital items in a database since it is quicker to find the item using the shorter hashed key than finding the items using the original value.

5 0
3 years ago
6.3.6: Adding to a Value codehs<br> help i don't know what to do .
QveST [7]

Question:

Write a function that adds together all values from 0 to a given value and returns the final number. For example, if the given value is `4`, you would add 0 + 1 + 2 + 3 + 4

Answer:

In Python:

def add_to_value(n):

   sum = 0

   for i in range(n+1):

       sum = sum + i

   

   return sum

Explanation:

This line defines the function

def add_to_value(n):

This line initializes sum to 0

   sum = 0

The following iteration adds from 0 to n

<em>    for i in range(n+1):</em>

<em>        sum = sum + i</em>

   

This line returns the calculated sum

   return sum

4 0
3 years ago
Other questions:
  • ?the single most effective security measure for digital devices is to password protect access to them.
    5·1 answer
  • In Rizzati Corp, vice presidents in departments such as engineering, manufacturing, IT, and human resources report directly to t
    15·1 answer
  • During an engine's intake stage, what passages inside the cylinder head of a gasoline powered engine must the incoming air-and-f
    10·1 answer
  • __________ is a collection of formatting options—such as a frame, a rounded shape, and a shadow—that changes a picture’s overall
    5·1 answer
  • Secure Multipurpose Internet Mail Extensions builds on the encoding format of the MIME protocol and uses digital signatures base
    15·1 answer
  • Need help with this
    6·1 answer
  • What is difference between computer and smartphone
    15·1 answer
  • Write a subclass called SavingsAccount that extends Account and adds an interest rate variable. Write a constructor with 3 argum
    6·1 answer
  • To stored three characters a computer occupies. Bytes memory space
    11·1 answer
  • question 2 which data link layer protocol defines the process by which lan devices interface with upper network layer protocols?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!