go to previous page   go to home page   go to next page hear noise

Answer:

Yes. Each of the three sums correctly calculated.


Adding Up Even and Odd Integers

Here is a skeleton for the program. Compare the skeleton to the flowchart at right.

Fill in the blanks so the program matches the flowchart.

First, get the counting loop correct. The loop should count from one up to (and including) the limit. It is often a good idea to write a program in stages (just as a house is built in stages).


flowchart of program
import  java.util.Scanner;

// User enters a value N
// Add up odd integers,  
// even  integers, and all integers 1 to N
//
class AddUpIntegers
{
  public static void main (String[] args ) 
  {
    Scanner scan = new Scanner( System.in );
    int N, sumAll = 0, sumEven = 0, sumOdd = 0;

    System.out.print( "Enter limit value:" );
    N = scan.nextInt();

    int count =  ;
    
    while (   )    
    {
      (more statements will go here later.)

       ;
    }

    System.out.print  ( "Sum of all : " + sumAll  );
    System.out.print  ( "\tSum of even: " + sumEven );
    System.out.println( "\tSum of odd : " + sumOdd  );
  }
}

QUESTION 4:

Fill in the three blanks.