// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.util.Scanner;

public class ScanDemo {
    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        int sum = 0;
        boolean done = false;
        while(!done) {
            System.out.print("Enter number or S: ");
            String line = scn.nextLine();
            if(line.equals("S")) {
                done = true;
            } else if(line.matches("^\\d+$")) {
                sum += Integer.parseInt(line);
            } else {
                System.out.println("Invalid input");
            }
        }
        System.out.println("The sum is: " + sum);
    }
}
