Assignemnt #67 Adding Values in a Loop
Code
Name: Iaroslav Titov
Period: 7
Project Name: Adding
File Name: Adding.java
Date: 11/10/2015
import java.util.Scanner;
import java.util.InputMismatchException;
import java.util.Random;
public class Adding
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int num = 0;
int total = 0;
System.out.print("I will add the numbers you give me.\n");
try
{
do
{
System.out.print("Number: ");
num = keyboard.nextInt();
total += num;
System.out.println();
if (num != 0) System.out.println("The total so far is "+total+".");
else System.out.println("The total is "+total+".");
System.out.println();
}
while (num!=0)
}
catch (InputMismatchException e)
{
System.out.println("WRONG INPUT!!!");
}
System.out.println();
}
}
Picture of the output