import java.io.*;

public class WhileExample


{

	public static void main (String args[]) throws IOException 

	{
	//uses while loop to add a series of positive numbers together
	//Compare with the doWhile example

		int nextnumber;
		int sum;
		int count;
	//create a bufferReader object to read the InputStreamReader
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

	//ensure that we run run through the while loop. If less that 0 will end 

		String s = new String();
		nextnumber = 0;
		sum=0;
		// initialise count to -1 so that it count correctly the number of times entries are added
		
		count = -1;
		while (nextnumber>-1)
		{

			count++; // increments by 1 the irst time through and sets it to 0
			sum+=nextnumber;
			System.out.println("Enter the next number, -1 to quit");	
			System.out.flush();

			s=in.readLine(); // read in the users input
			Integer I = new Integer(s); // converts it to an integer
			nextnumber = I.intValue(); // assign it next number
		} // ends the while loop
	System.out.println (" You have added together " + count + " numbers");
	System.out.println ("The total is = " +sum);

	}// ends the main

}// ends the class