Complete Program

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page        

Answer:

The finished program is given below.

Complete Program

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.

QUESTION 11:

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?