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.

Physics for Scientists and Engineers: Foundations and Connections
1st Edition
ISBN:9781133939146
Author:Katz, Debora M.
Publisher:Katz, Debora M.
Chapter1: Getting Started
Section: Chapter Questions
Problem 8PQ: In Jules Vernes novel, Twenty Thousand Leagues Under the Sea, Captain Nemo and his passengers...
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Physics for Scientists and Engineers: Foundations…
Physics for Scientists and Engineers: Foundations…
Physics
ISBN:
9781133939146
Author:
Katz, Debora M.
Publisher:
Cengage Learning
Classical Dynamics of Particles and Systems
Classical Dynamics of Particles and Systems
Physics
ISBN:
9780534408961
Author:
Stephen T. Thornton, Jerry B. Marion
Publisher:
Cengage Learning
College Physics
College Physics
Physics
ISBN:
9781305952300
Author:
Raymond A. Serway, Chris Vuille
Publisher:
Cengage Learning