You need to read more numbers. You read one value before your loop. You could do something like
int number; while((number = input.nextInt()) != 0) { total += number; count++; if(number > 0){ positive++; } else if(number < 0) { negative++; } } // <-- end loop body. float average = total / (float) count; // <-- not integer math. System.out.println("The number of positives is " + positive); System.out.println("The number of negatives is " + negative); System.out.println("The total is " + total); System.out.println("The average is " + average);
Related Posts:
- Can’t find mysqladmin on Mac OSX 10.6.8
- Integer range when using 64bit jdk
- How to get rid of Checkstyle message ‘File does not end with a newline.’
- InvocationTargetException when running a javafx program
- Netbeans installation doesn’t find JDK
- JDK was not found on the computer for NetBeans 6.5
- Sending mail error, javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;
- Why is Netbeans suggesting I “Flip operands of the binary operators” in my Java code
- Popup Message boxes
- Netbeans – Error: Could not find or load main class
- Exception in thread “main” java.net.BindException: Address already in use – Error in Netbeans only
- How do I autoindent in Netbeans?
- Issue installing Netbeans in Windows 10: Java SE Development Kit (JDK) was not found on this computer
- No Main class found in NetBeans
- What is a stack trace, and how can I use it to debug my application errors?
- How to fix “A JNI error has occurred, please check your installation.”
- Java Runtime Environment not found error when I open an application
- “PKIX path building failed” and “unable to find valid certification path to requested target”
- What exactly does a jar file contain?
- What is the best way to implement constants in Java?
- What is the reason behind “non-static method cannot be referenced from a static context”?
- What does ” || ” mean in Java? [duplicate]
- “Error occurred during initialization of VM; Could not reserve enough space for object heap” using -Xmx3G
- “int cannot be dereferenced” in Java
- What is a Key-Value Pair?
- Understanding Spring @Autowired usage
- What is a serialVersionUID and why should I use it?
- SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder”
- The difference between += and =+
- exception in initializer error in java when using Netbeans
- error upon assigning Layout: BoxLayout can’t be shared
- Why do this() and super() have to be the first statement in a constructor?
- Else without if
- Keytool is not recognized as an internal or external command
- Cannot find “Package Explorer” view in Eclipse
- Error: Could not find or load main class in intelliJ IDE
- Java Hashmap: How to get key from value?
- Understanding the difference between null and ‘\u000’ in Java
- what does Dead Code mean under Eclipse IDE Problems Section
- Java compressing Strings
- restart console on Minecraft Server
- SSL peer shut down incorrectly in Java
- Java split string to array
- How can I clear or empty a StringBuilder?
- Generate a random double in a range
- Eclipse “Error: Could not find or load main class”
- How to get locator of current web element?
- javax.naming.NameNotFoundException
- How to print out all the elements of a List in Java?
- If Java is Strongly typed then why does this code compile?
- Converting String Array to an Integer Array
- How to fix “unsupported class file major version 60” in IntelliJ?
- Resize an Array while keeping current elements in Java?
- Access restriction: The type ‘Application’ is not API (restriction on required library rt.jar)
- Assign the negativeCntr with the number of negative values in the linked list
- intellij incorrectly saying no beans of type found for autowired repository
- Web server failed to start. Port 8080 was already in use. Spring Boot microservice
- No Persistence provider for EntityManager named
- What does it mean: JavaFX application class must extend javafx.application.Application?
- Using Math.round to round to one decimal place?
- How to replace a substring of a string
- accessing a variable from another class
- How to check if object is null or not except == null
- Comparing strings by their alphabetical order
- exposed beyond app through ClipData.Item.getUri
- Java – get the current class name?
- Warning: The method assertEquals from the type Assert is deprecated
- koch snowflake java recursion
- Java word count program
- How to return a boolean method in java?
- Java read file and store text in an array
- MultipartException: Current request is not a multipart request
- How to extract a substring using regex
- .class vs .java
- Case expressions must be constant expressions for static final int?
- How to “wait” a Thread in Android
- How to use regex in String.contains() method in Java
- Error: Module not specified (IntelliJ IDEA)
- Checking letter case (Upper/Lower) within a string in Java
- How to swap String characters in Java?
- Exception in thread “main” java.net.ConnectException: Connection refused: connect Socket Programming Java
- Why is there no multiple inheritance in Java, but implementing multiple interfaces is allowed?
- Resource leak: ‘in’ is never closed
- JavaFX and OpenJDK
- What’s the difference between JPA and Hibernate?
- Java console program
- “Source folder is not a Java project” error in eclipse
- How to memory profile in Java?
- java.lang.IllegalThreadStateException
- What is an
method in Java? Can it be overridden? - The sum of all squares between 1 and 100 inclusive?
- How do I initialize a byte array in Java?
- How to extract .war files in java? ZIP vs JAR
- What is the difference between run-time error and compiler error?
- What is the difference between ArrayList.clear() and ArrayList.removeAll()?
- Test if element is present using Selenium WebDriver?
- Increase heap size in Java
- android.content.res.Resources$NotFoundException: String resource ID #0x0
- what does x– or x++ do here?
- How to specify filepath in java?