Advertisement
476179

soccerpoints -loops5

Nov 21st, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. package les;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class SoccerPoints
  6. {
  7. // calcs total point over series of games , user enters points then -1 to signify end of list
  8. public static void main(String[] args)
  9. {
  10. Scanner k = new Scanner(System.in);
  11.  
  12. System.out.print("enter number of points team earned each game "
  13. + "\nthen enter \"-1\" when finshed: ");
  14. int points = k.nextInt();
  15. int total = 0;
  16.  
  17.  
  18. while (points != 0 )
  19. {
  20. System.out.print("enter game points or \"-1\" to end: ");
  21. points = k.nextInt();
  22. total += points;
  23. //"total" var is an accumulator variable
  24. }
  25. System.out.println("total points team has earned is: "+total);
  26.  
  27.  
  28. k.close();
  29. // -1 is the sentinal value, it tells program we reached end of
  30. //list and to stop program and add total points
  31. }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement