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