The finished program is given below.
Here is the finished program:
import java.util.Scanner;
class AddUpFile
{
public static void main ( String[] args )
{
Scanner scan = new Scanner( System.in );
int value;
int sum = 0 ; // initialize sum
int count = 1 ; // initialize count
while ( count <= 100 )
{
System.out.print("Enter a number: ") ;
value = scan.nextInt() ;
sum = sum + value; // add to the sum
count = count + 1 ; // increment count
}
System.out.println( "Grand Total: " + sum );
}
}
If you run this program as is you will have to enter 100 integers. This could be tedious. For testing purposes you can change the "100" to a smaller number.
Say that you do have a file of 100 integers and run the program by doing this:
C:\java AddUpFile < largeData.txt
What will the user see on the monitor?