0
2.5kviews
write the program that computes sum of list of integers that is supplied by a user. The end of the data is signaled by the value - 999. This value is used only as a flag and not used in sum.

Mumbai University > Information Technology > Sem 3 > Object Oriented Programming Methodology

Marks: 10 M

Year: Dec 2014

1 Answer
0
66views
Import java.io.*;
Import java.util.*;
Public class AdditionAgain
{
Public static void main (String args[])
    {
    Scanner input = new Scanner(System.in);
        final int FLAG = -999; //signals the end of the data 
        int sum = 0;
        int num;
        System.out.println(“Enter the numbers .End with”+FLAG);
        num = Input.nextInt();
        while (num != FLAG)
        {
            sum = sum + num; //adds the current integer to sum
            num = Input.nextInt ();
        }
        System.out.println(“Sum: ”+sum);}}
    }
}
Please log in to add an answer.