go to previous page   go to home page   go to next page
12  7   -4    6

Answer:

The program will run without complaint and scan the first two numbers, add them, and output the result. It will then stop, without looking at he last two numbers.


Addition Program

Say that you have a file containing exactly 100 integers (as characters), one per line. You wish to add up all these integers. Write a program to read from keyboard input.

Once it has been tested and debugged, use the program with the input file. Here is a start on the program:


import java.util.Scanner;

class AddUpFile
{
  public static void main ( String[] args )  
  {
    Scanner scan = new Scanner( System.in );
    int value;
    int sum = ; // initialize sum

    int count = ; // initialize count
    
    while ( count  100 )
    {
      System.out.print("Enter a number: ");
      value  = scan.nextInt();
      sum    = ; // add to the sum
      
      count  = ; // increment count
    }

    System.out.println( "Grand Total: " + sum );
  }
}


QUESTION 10:

Fill in the blanks.


go to previous page   go to home page   go to next page