Write a JAVA program that keeps asking the user for numbers, until the user enters 0. After the user enters 0, the program should display the number of negative and positive numbers entered. (I already wrote the code but it is not working, the output is just blank. I need help seeing what is going wrong in it.

College Physics
11th Edition
ISBN:9781305952300
Author:Raymond A. Serway, Chris Vuille
Publisher:Raymond A. Serway, Chris Vuille
Chapter1: Units, Trigonometry. And Vectors
Section: Chapter Questions
Problem 1CQ: Estimate the order of magnitude of the length, in meters, of each of the following; (a) a mouse, (b)...
icon
Related questions
Question
  1. Write a JAVA program that keeps asking the user for numbers, until the user enters 0. After the user enters 0, the program should display the number of negative and positive numbers entered. (I already wrote the code but it is not working, the output is just blank. I need help seeing what is going wrong in it.


import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    //creates a new scanner object
    int n=1;
    int negative_count=0;
    //stores and counts the negative numbers
    int positive_count=0;
    //stores and counts the positive numbers
    while (n!=0) {
    // the stopping condition is zero.
        n=sc.nextInt();
        if (n<0){
            negative_count=negative_count+1;
        }
        else if (n>0){
            positive_count=positive_count+1;
        }
       
    }  
    System.out.println("Program Stopped Because User Entered Zero :( ");
    System.out.println("Total Amount of Inputted Positive Numbers: "+positive_count);
    System.out.println("Total Amount of Inputted Negative Numbers:  "+negative_count);
  }
}

Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Height and distance
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, physics and related others by exploring similar questions and additional content below.
Recommended textbooks for you
College Physics
College Physics
Physics
ISBN:
9781305952300
Author:
Raymond A. Serway, Chris Vuille
Publisher:
Cengage Learning
University Physics (14th Edition)
University Physics (14th Edition)
Physics
ISBN:
9780133969290
Author:
Hugh D. Young, Roger A. Freedman
Publisher:
PEARSON
Introduction To Quantum Mechanics
Introduction To Quantum Mechanics
Physics
ISBN:
9781107189638
Author:
Griffiths, David J., Schroeter, Darrell F.
Publisher:
Cambridge University Press
Physics for Scientists and Engineers
Physics for Scientists and Engineers
Physics
ISBN:
9781337553278
Author:
Raymond A. Serway, John W. Jewett
Publisher:
Cengage Learning
Lecture- Tutorials for Introductory Astronomy
Lecture- Tutorials for Introductory Astronomy
Physics
ISBN:
9780321820464
Author:
Edward E. Prather, Tim P. Slater, Jeff P. Adams, Gina Brissenden
Publisher:
Addison-Wesley
College Physics: A Strategic Approach (4th Editio…
College Physics: A Strategic Approach (4th Editio…
Physics
ISBN:
9780134609034
Author:
Randall D. Knight (Professor Emeritus), Brian Jones, Stuart Field
Publisher:
PEARSON