Program #67

Code

   
    /// Name: Afaf Nabeeha
    /// Period: 7
    /// Program Name: Adding Values in a Loop
    /// File Name: Values.java
    /// Date Finished: 12/16/2015 public class Values


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

Picture of the output

Assignment 67