Assignment 67: Adding Values in a While Loop

Code

    /// Name: Ryan McAteer
    /// Period: 5
    /// Program Name: Adding Values in a Loop
    /// File Name: Assignment67.java
    /// Date Finished: 12/10/15
    
    import java.util.Scanner;

public class Assignment67
{
    public static void main ( String[] args )
	{
		int chosenNumber, previousNumber, total;
        previousNumber = 0;
        
        Scanner keyboard = new Scanner(System.in);
        
        System.out.println("I will add up the numbers you give me.");
        System.out.print("Number: ");
        chosenNumber = keyboard.nextInt();
        total = previousNumber + chosenNumber;
        System.out.println("The total is " + total + ".");
        previousNumber = total;
        
        while ( chosenNumber != 0 )
        {
            System.out.print("Number: ");
            chosenNumber = keyboard.nextInt();
            total = previousNumber + chosenNumber;
            System.out.println("The total is " + total + ".");
            previousNumber = total;  
        }
        
        if ( chosenNumber == 0 )
        {
            System.out.println();
            System.out.println("Your total is " + total + ".");
        }
    }
}
    

Picture of the output

This Should Work