Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package les;
- import java.util.Scanner;
- public class SoccerPoints
- {
- // calcs total point over series of games , user enters points then -1 to signify end of list
- public static void main(String[] args)
- {
- Scanner k = new Scanner(System.in);
- System.out.print("enter number of points team earned each game "
- + "\nthen enter \"-1\" when finshed: ");
- int points = k.nextInt();
- int total = 0;
- while (points != 0 )
- {
- System.out.print("enter game points or \"-1\" to end: ");
- points = k.nextInt();
- total += points;
- //"total" var is an accumulator variable
- }
- System.out.println("total points team has earned is: "+total);
- k.close();
- // -1 is the sentinal value, it tells program we reached end of
- //list and to stop program and add total points
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement