SumEvens - public static void main(String args int sum = 0...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
//******************************************************************** // SumEvens.java Author: Lewis and Loftus // // Solution to Programming Project 3.4 //******************************************************************** / import java.util.Scanner; i public class SumEvens { //----------------------------------------------------------------- // Computes and prints the sum of the even values between 2 and // a positive value entered by the user. //-----------------------------------------------------------------
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: public static void main (String args) { int sum = 0, value; System.out.print ("Enter a positive integer: "); Scanner sc = new Scanner(System.in); value = sc.nextInt(); if (value < 2) System.out.println ("The value must be greater than two."); else { for (int count = 2; count <= value; count+=2) sum += count; System.out.println ("The sum of the even integers from 2 to " + value + " is " + sum); } } }...
View Full Document

Ask a homework question - tutors are online