Advertisement
lleu

Untitled

Sep 25th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Counts {
  4.  
  5. public static void main(String[] args) {
  6. // TODO Auto-generated method stub
  7.  
  8. //Assign variables
  9.  
  10. int posNum = 0, negNum = 0, totalEntered = 0, totalCount = 0;
  11. int userInput;
  12. int averageEntered;
  13.  
  14. //Begin user input
  15.  
  16. Scanner input = new Scanner(System.in);
  17. System.out.println("Please enter as many whole numbers as you would like. Enter 0 to end the program and get your results");
  18.  
  19. //Do while loop
  20.  
  21. do { userInput = input.nextInt();
  22. totalEntered += userInput;
  23. totalCount++;
  24. if(userInput > 0) {
  25. posNum++;}
  26.  
  27. else if(userInput < 0){
  28. negNum++;}
  29.  
  30. }
  31. while(userInput != 0);
  32.  
  33. averageEntered = totalEntered / totalCount;
  34.  
  35. //Output
  36. System.out.println("You entered " + totalCount + " numbers");
  37. System.out.println("You entered " + posNum + " positive numbers");
  38. System.out.println("You entered " + negNum + " negative numbers");
  39. System.out.println("The total of the numbers entered was "+ totalEntered);
  40. System.out.println("And the average of the numbers was "+ averageEntered);
  41.  
  42. //Close user input
  43. input.close();
  44. }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement