Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need to edit the following JAVA code so that if the entire input is 0, the program displays No numbers are entered except 0.

I need to edit the following JAVA code so that if the entire input is 0, the program displays "No numbers are entered except 0". Otherwise the outputs and functions should remain the same.

import java.util.Scanner; import java.util.*; import java.text.*;

public class Exercise05_01 {

/** * @param args the command line arguments */ public static void main(String[] args) { Scanner scan = new Scanner(System.in); //declare variagbles int total = 0; double average = 0.0; int numOfNeg = 0; int numOfPos = 0; int numOfValues = 0; int value; //user input System.out.print("Enter an integer, the input ends if it is 0: "); do { //read all of the input numbers (unlimited until user prompts stop) value = scan.nextInt(); //determine positive or neg //add to count //if positive if (value>0){ numOfPos++; numOfValues++; total+=value; }//end if positive //if negative else if(value<0){ numOfNeg++; numOfValues++; total+=value; }//end if negative //start loop if there is no zero } while (value != 0); { DecimalFormat dec=new DecimalFormat("#,###.##"); average=total/numOfValues; System.out.println("The number of postitives is "+numOfPos); System.out.println("The number of negatives is "+numOfNeg); System.out.println("The total is "+total);; System.out.println("The average is "+dec.format(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

Step: 3

blur-text-image

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

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions

Question

2. What was to be the desired outcome of the restructurings?

Answered: 1 week ago