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

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!