Assignemnt #67 and Adding Values in a Loop
Code
/// Name: Marco Correa
/// Period: 5
/// Program Name: Adding Values in a Loop
/// File Name: AddingValuesLoop.java
/// Date Finished: 1/9/2016
import java.util.Scanner;
public class AddingValuesLoop
{
public static void main(String[]args)
{
Scanner keyboard = new Scanner(System.in);
System.out.println("I will add up the numbers you give me.");
System.out.print("Number: ");
int number = keyboard.nextInt();
int total = number;
while (number !=0)
{
System.out.println("Your total so far is " + total );
System.out.print("Number: ");
number = keyboard.nextInt();
total = total + number;
}
System.out.println("\nThe total is " + total + ".");
}
}
Picture of the output