subject

This project deals with EOF-based loops, using the while construct where we do not know the exact number of times a loop will iterate (perform the associated block of code). We will continue to build on our knowledge of if/else constructs.

Use the variables given below to solve the problem. You should need no other variables to complete this project.

// number entered and the running total

int inputNum, sum = 0;

// count of valid and invalid numbers seen

int numValid = 0, numInvalid = 0;

double average;

Using your knowledge of Java and using inputNum as your input variable, write a while loop to read positive integers from the user until the user enters the EOF character. This is the sentinel value indicating that the user has finished entering data.

You can use hasNext() to determine if the EOF has occurred. The user must use CTRL-D (DrJava) to terminate the program since these are the appropriate EOF characters.

Numbers will be separated into two categories. Valid numbers are considered to be the range of positive integers including zero. Invalid numbers are the range of negative integers.

As you are reading in the values you should be keeping track of how many positive values (numValid) have been read while simultaneously keeping a running total (sum).

You should not include negative values in the running total. Instead you should increment the count of invalid numbers (numInvalid) entered by the user.

You will report to the user the number of valid values they entered, the number of invalid values, the sum and average of the valid values. The average should be displayed as a floating point value to two decimal places using the printf() method.

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 18:30
Technician a says that a shop towel should never be used to clean around the flange area before replacing an automatic transmission filter. technician b says that a dimpled transmission fluid pan can be repaired. who is right
Answers: 3
question
Computers and Technology, 22.06.2019 21:00
So im doing this school challenge and the teachers said whats the average text a student gets a day so i need to get about 20 in a day but dont know how can you guys 2163371293
Answers: 2
question
Computers and Technology, 23.06.2019 00:00
Which is the correct sequence of steps to set up a document in landscape orientation? a. select page setup from the file menu. then click the margins tab and select landscape. b. select page setup from the edit menu. then click the margins tab and select landscape. c. select page setup from the insert menu. then click the margins tab and select landscape. d. select page setup from the format menu. then click the margins tab and select landscape
Answers: 1
question
Computers and Technology, 23.06.2019 17:10
Ac++an of of pi. in , pi is by : pi = 4 – 4/3 + 4/5 – 4/7 + 4/9 - 4/11 + 4/13 - 4/15 + 4/17 . ., to pi (9 ). , if 5 to pi,be as : pi = 4 - 4/3 + 4/5 - 4/7 + 4/9 = 4 – 1. + 0.8 - 0. + 0. = 3.. atoofbe to pi?
Answers: 2
You know the right answer?
This project deals with EOF-based loops, using the while construct where we do not know the exact nu...
Questions
question
Mathematics, 13.10.2020 09:01
question
Mathematics, 13.10.2020 09:01
question
Mathematics, 13.10.2020 09:01
question
Arts, 13.10.2020 09:01
question
Mathematics, 13.10.2020 09:01
Questions on the website: 13722361