package Chap3;
import java.io.*;

// CSC108 Chapter 3, Question 16
// Name:  Iam Me         Student ID: 555555555
// Tutor: Andria Hunter  Prof: Ken Jackson
//
// Program Description: Reads an integer value and prints
//     the sum of all even integers between 2 and the input
//     value, inclusive.

class q16 {

   // Main method to read the integer value and print the sum.

   public static void main (String[] args) throws IOException {

      // Declare stdin so data can be read from input.
      DataInputStream stdin = new DataInputStream (System.in);

      final int START = 2;     // starting value of sum

      int value;               // integer value read from input

      // Read the integer value from stdin
      System.out.println ("Enter an integer value (>="+START+"): ");
      value = Integer.parseInt(stdin.readLine());

      // Report error if invalid integer is entered.
      if (value < START) {
         System.out.print ("Invalid integer.  ");
         System.out.println ("Must be greater than or equal to "+START);
      }

      else {
         int count = 1;           // counts each even number
         int sum = 0;             // sums up each even number

         // Calculate the sum of all even numbers up to the integer entered.
         while (count <= value/2) {
            sum = sum + count*2;
            count = count + 1;
         }

         System.out.print ("The sum of all even numbers from "+START);
         System.out.println (" up to "+value+" is "+sum);
      }
   }
}

