Assignment #67 and Adding Values in a Loop
Code
/// Name: Lauren Baird
/// Period: 7
/// Program Name: Adding Values in a Loop
/// File Name: LoopValues.java
/// Date Finished: 11/6/2015
import java.util.Random;
import java.util.Scanner;
public class LoopValues
{
public static void main( String[] args )
{
Random r = new Random();
Scanner keyboard = new Scanner(System.in);
int t = 0;
System.out.println();
System.out.println( "I will add up the numbers you give me." );
System.out.print( "Number: " );
int number = keyboard.nextInt();
t = t + number;
if ( number != 0 )
System.out.println( "The total so far is " + t );
while ( number != 0 )
{
System.out.print( "Number: " );
number = keyboard.nextInt();
t = t + number;
if ( number != 0 )
System.out.println( "The total so far is " + t );
}
System.out.println();
System.out.println( "The total is " + t );
System.out.println();
}
}