Assignment #67 and Adding Values in a Loop
Code
/// Name: Ali Kurland
/// Period: 6
/// Program Name: Adding Values in a Loop
/// File Name: AddingValues.java
/// Date Finished: 10/13/2015
import java.util.Scanner;
public class AddingValues
{
public static void main ( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int number, total;
System.out.println( "I will add up the numbers you give me." );
System.out.print( "Number: " );
number = keyboard.nextInt();
total = number;
while ( number != 0 )
{
System.out.println( "The total so far is " + total );
System.out.print( "Number: " );
number = keyboard.nextInt();
total = total + number;
}
if ( number == 0 )
System.out.println( "\nThe total is " + total + "." );
}
}
Picture of the output