Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Counts {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- //Assign variables
- int posNum = 0, negNum = 0, totalEntered = 0, totalCount = 0;
- int userInput;
- int averageEntered;
- //Begin user input
- Scanner input = new Scanner(System.in);
- System.out.println("Please enter as many whole numbers as you would like. Enter 0 to end the program and get your results");
- //Do while loop
- do { userInput = input.nextInt();
- totalEntered += userInput;
- totalCount++;
- if(userInput > 0) {
- posNum++;}
- else if(userInput < 0){
- negNum++;}
- }
- while(userInput != 0);
- averageEntered = totalEntered / totalCount;
- //Output
- System.out.println("You entered " + totalCount + " numbers");
- System.out.println("You entered " + posNum + " positive numbers");
- System.out.println("You entered " + negNum + " negative numbers");
- System.out.println("The total of the numbers entered was "+ totalEntered);
- System.out.println("And the average of the numbers was "+ averageEntered);
- //Close user input
- input.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement