Assignemnt #67 and Adding Values In a Loop
Code
/// Name: Kyle Ivy
/// Period: 5
/// Program Name: ValueLoop
/// File Name: ValueLoop.java
/// Date Finished: 1/5/2016
import java.util.Scanner;
import java.util.Random;
public class ValueLoop {
public static void main( String[] args ) {
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int n, sum;
sum = 0;
System.out.println( "I will add up the numbers you give me. ");
System.out.print( "Number: ");
n = keyboard.nextInt();
while ( n != 0 )
{
sum = n + sum;
System.out.println("The total so far is " + sum );
System.out.print( "Number: ");
n = keyboard.nextInt();
}
if ( n == 0 )
System.out.println( "The total is " + sum );
}
}
prog67.PNG