Assignment #67 Adding Values in a Loop
Code
///Name: Ian Grant
///Period:5
///Project Name: Adding Values in a Loop
///File Name:AddLoop.java
///12/02/15
import java.util.Scanner;
public class AddLoop
{
public static void main(String[] args)
{
Scanner stuff= new Scanner(System.in);
int num;
int sum=0;
System.out.println("I will add up the numbers you give me.");
System.out.print("Number: ");
num=stuff.nextInt();
sum= sum + num;
while (num!=0)
{
System.out.println("The total so far is "+sum);
System.out.print("Number: ");
num=stuff.nextInt();
sum=sum+num;
}
System.out.println("The total so far is "+sum);
}
}
Output