Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ==> Close All Projects). Then create

First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ==> Close All Projects).

Then create a new Java application called "Averager" (without the quotation marks) to get positive (i.e., any number greater than 0), double numbers from the user at the command line until they enter -1 (the sentinel). Use a do-while loop. Compute the average of the series of numbers and print the average to the command line. Don't include the sentinel in calculation of the average. Include suitable data validations for invalid data (e.g. the user enters a letter instead of a number), but stay in the loop until the sentinel is entered.

package averager; import java.util.Scanner; public class Averager {

public static void main(String[] args) { // TODO code application logic here int i,counter=0,sum=0; double avg;

Scanner keyboard = new Scanner(System.in); //true or flase value do { System.out.println("Enter the integer : "); //repeat the numbers enter its a validate while(!keyboard.hasNextInt()){ keyboard.next(); System.out.println("Enter number only"); } i = keyboard.nextInt(); if(i == -1) break; ////increment counter else { sum = sum +i; counter++;

} } while(i != 0); avg = (double)sum/(double)counter; System.out.printf("Average = %.2f",avg);

}

}

not sure if its right please help thanks

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And Implementation

Authors: Edward Sciore

2nd Edition

3030338355, 978-3030338350

More Books

Students also viewed these Databases questions

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago