Assignemnt 67: Adding Values with While Loops
Code
/// Name: Sean Harrison
/// Period: 7
/// Program name: Adding Values with While Loops
/// File Name: AddingValues.java
/// Date Finished: 12/16/2015
import java.util.Scanner;
public class AddingValues
{
public static void main( String[] args )
{
int NewNumber, LastNumber, Total;
Scanner keyboard = new Scanner(System.in);
LastNumber = 0;
System.out.println( "I will sum all numbers you give me " );
System.out.println( " Number : " );
NewNumber = keyboard.nextInt();
Total = ( NewNumber + LastNumber );
System.out.println ( " Your total value is " + Total );
LastNumber = Total;
while ( NewNumber != 0 )
{
System.out.print( "Number: " );
NewNumber = keyboard.nextInt();
Total = LastNumber + NewNumber;
System.out.println( "The total so far is " + Total );
LastNumber = Total;
}
if ( NewNumber == 0 )
{
System.out.println( " The total is " + Total );
}
}
}
Picture of the output