Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!