Question

JAVA QUESTION

Ex 17: Average Scanner Started: May 20 at 11:08pm Quiz Instructions D Question 1 1 pts Write a method averageScanner that reads in double values from an argument Scanner as long as the Scanner indicates that there is a double value to read. The method returns a double indicating the average (mean) of the double values provided by the Scanner. You may assume the Scanner provides at least one double value.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Java program:

import java.util.Scanner;

public class AverageFinder

{

//class variables to hold data

static double sum=0,avg=0;

static int count=0;

//main method

public static void main(String[] args)

{

//Scanner class object to read values

Scanner in = new Scanner(System.in);

System.out.println("Enter double values,-1 to quit");

double values=0;

  

//while loop to enter values till input is -1

while((values= in.nextInt()) != -1)

{

//calling method

avg=averageScanner(values);

}

//printing the output to console

System.out.println("Average="+avg);

}

//method reading double values from scanner and returning mean

public static double averageScanner(double values)

{

//summing the values

sum=sum+values;

//to count number of values read in

count++;

//finding average

avg=sum/count;

//returning average

return avg;

}

}

Add a comment
Know the answer?
Add Answer to:
JAVA QUESTION Ex 17: Average Scanner Started: May 20 at 11:08pm Quiz Instructions D Question 1...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • ueNature vs. Nurture Quiz Nature vs. Nurture Quiz Started: May 23 at 6:08pm Quiz Instructions D Question 1 1 pts We...

    ueNature vs. Nurture Quiz Nature vs. Nurture Quiz Started: May 23 at 6:08pm Quiz Instructions D Question 1 1 pts Wesley believes that it is his strong work ethic-learned from his mother - that allows him to succeed in Introduction to Psychology Atten 59 M O Nature Both O Nurture Next Quiz saved at 6:08pm Submit Quiz ueNature vs. Nurture Quiz Nature vs. Nurture Quiz Started: May 23 at 6:08pm Quiz Instructions D Question 1 1 pts Wesley believes that...

  • Started: Jan 7 at 10:08pm Quiz Instructions D Question 18 1 pts How can measurements of...

    Started: Jan 7 at 10:08pm Quiz Instructions D Question 18 1 pts How can measurements of income inequality be misleading to politicians and economists? O There is no agreement as to what constitutes income inequality. O Most developed economies employ wealth redistribution systems, which skew the effect wealth has on income inequality. O All statistics regarding income inequality give disproportionate weight to factors like corruption and wealth O Income inequality is difficult to measure and easy to misinterpret O Since...

  • HW Chapter 8 [Spring 2019] Started: Mar 17 at 7:24pm Quiz Instructions Question 16 1 pts...

    HW Chapter 8 [Spring 2019] Started: Mar 17 at 7:24pm Quiz Instructions Question 16 1 pts The mean square is: O all of the provided answers D calculated by dividing the sum of squares between by the degrees of freedom between. calculated by dividing the sum of squares within by the degrees of freedom within. is a method for assessing variation in conjunction with the sums of squares measures. Previous Next HW Chapter 8 [Spring 2019] Started: Mar 17 at...

  • Thermo Quiz Started: May 16 at 11:52am Quiz Instructions D Question 5 1 pts For the...

    Thermo Quiz Started: May 16 at 11:52am Quiz Instructions D Question 5 1 pts For the synthesis of ammonia by the Haber process: N2(g)3H2g)>2NH3(g) Using the attached data, calculate AG at 298K in kJ/mol. Given: =-32.7 (kJ/mol) PN2 200 atm PH2 600 atm PNH3 200 atm 16 3 4 5 6 8 9

  • Quiz 4 Started: Feb 7 at 11:36am Quiz Instructions D Question 6 1 pts Animals are...

    Quiz 4 Started: Feb 7 at 11:36am Quiz Instructions D Question 6 1 pts Animals are the only Eukaryotes (organisms with membrane bound organelles and DNA contained within a nucleus) True False Next > . Previous

  • part one : Review Exercises 1. Write method called raggedCount that takes an integer n as...

    part one : Review Exercises 1. Write method called raggedCount that takes an integer n as argument and returns a ragged array of n rows of lengths 1, 2, 3, 4, ... , n and the whole array has the integers 1, 2, 3, 4, ... , n(n+1) 2 in row order. For example, raggedCount(4) should return the array: 1 2 3 4 5 6 7 8 9 10 1 2. Write a method called arrayConcat that takes as argument...

  • This is a java file and I am very confused on how to do this project!...

    This is a java file and I am very confused on how to do this project! please help!! Specifications Overview: You will write a program this week that is composed of three classes: the first class defines Ellipsoid objects, the second class defines EllipsoidList objects, and the third, Ellipsoid ListApp, reads in a file name entered by the user then reads the list name and Ellipsoid data from the file, creates Ellipsoid objects and stores them in an ArrayList of...

  • This interactive program focuses on if/else statements, Scanner, and returning values. Turn in a file named...

    This interactive program focuses on if/else statements, Scanner, and returning values. Turn in a file named Budgeter.java. To use a Scanner for console input, you must import java.util.*; in your code. This program prompts a person for income and expense amounts, then calculates their net monthly income. Below are two example logs of execution from the program. This program’s behavior is dependent on the user input (user input is bold and underlined below to make it stand out and differentiate...

  • Copy the following java codes and compile //// HighArray.java //// HighArrayApp.java Study carefully the design and...

    Copy the following java codes and compile //// HighArray.java //// HighArrayApp.java Study carefully the design and implementation HighArray class and note the attributes and its methods.    Create findAll method which uses linear search algorithm to return all number of occurrences of specified element. /** * find an element from array and returns all number of occurrences of the specified element, returns 0 if the element does not exit. * * @param foundElement   Element to be found */ int findAll(int...

  • INSTRUCTIONS: I NEED TO CREATE A PointApp PROGRAM THAT USES THE FOLLOWING API DOCUMENTATION. Below the...

    INSTRUCTIONS: I NEED TO CREATE A PointApp PROGRAM THAT USES THE FOLLOWING API DOCUMENTATION. Below the API Documentation is the code I submitted. However, the output is different for what they are asking. I am looking for someone to fix the code to print out the correct output and to add comments so I can have an idea in how the code works. PLEASE AND THANK YOU. API DOCUMENTATION: public class Point extends java.lang.Object The Point class is used to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT