Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have no idea how to do this loping problem in Java. Someone please help me. For this example looping programming problem you will need

I have no idea how to do this loping problem in Java. Someone please help me.

For this example looping programming problem you will need to add in the code to finish the programming problem and find the min and average. After adding in the code to make it work you will turn in your code to this assignment in Canvas,

Problem: (Count positive and negative numbers and compute the average of numbers) Write a program that reads an unspecified number of integers , determines how many positive and negative values have been read, and computes the total and average of the input values (not counting zeros). Your program ends with the input 0. Display the average as a floating-point number.

import java.util.Scanner;

public class CountingNumbers {

public static void main(String[] args) {

int countPositive = 0;

int countNegative = 0;

//start max at something really small so that something can be bigger than it

int max = 0;

//start min at something really big so that something can be smaller than it

int min = 0;

//used to hold the average

double average = 0;

int count = 0; //used to count the numbers so that we can find the average

int sum = 0; //start sum at 0 so that we can add to them

Scanner input = new Scanner(System.in);

//prompt the user to enter grade numbers and finish with a negative score

System.out.println("Please enter in some numbers, and 0 to quit");

int number = input.nextInt(); //get the first input and then check if it is not 0

while (number != 0) {

sum += number; //add the number to the sum

count++;

if (number > max) //see if the new number is bigger than the current max

max = number;

if(number > 0)//check to see if it positive

countPositive++;

if(number < 0)//check to see if it positive

countNegative++;

number = input.nextInt(); //get the next number

}

//print out the results

System.out.println("Number of positive numbers: " + countPositive);

System.out.println("Number of positive numbers: " + countNegative);

System.out.println("Max: " + countNegative);

System.out.println("Min: " + countNegative);

//find the average

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

}

}

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

Professional Microsoft SQL Server 2014 Administration

Authors: Adam Jorgensen, Bradley Ball

1st Edition

111885926X, 9781118859261

More Books

Students also viewed these Databases questions

Question

How does a writ of execution work?

Answered: 1 week ago

Question

\f

Answered: 1 week ago