Assignment #67 Adding Values in a Loop
Code
/// Name: Koosha Kimelman
/// Period: 7
/// Program Name: Adding Values in a Loop
/// File Name: AddingValues.java
/// Date Completed: 11/10/15
import java.util.Scanner;
public class AddingValues {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int number, total;
total = 0;
System.out.println("I will add up the numbers you give me. Type in a 0 when you are done.");
System.out.print("Number: ");
number = keyboard.nextInt();
while (number != 0) {
total = (total+number);
System.out.println("The total so far is " + total + ".");
System.out.print("Number: ");
number = keyboard.nextInt();
}
System.out.println("The total is " + total + ".");
}
}
Picture of the output