Assignemnt #67: Adding Values in a Loop

Code

    /// Name: Kelsey Lieberman
    /// Period 5
    /// Program Name: AddingValuesLoop
    /// File Name: AddingValuesLoop.java
    /// Date Finished: 12/8/2015
    
import java.util.Scanner;

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

Picture of the output

Assignment 67