Friday, August 9, 2013

Java Program 003

Write a program to print sum of all even numbers between given numbers.


// Author : J. Srivastav Reddy
// Date : 30-7-2013

public class SumOfEvenNumbersInBetween
{
public static void main(String[] args)
{
int start = Integer.parseInt(args[0]) + 1;

int
stop = Integer.parseInt(args[1]);
                int sum = 0;
for (; start < stop; start ++)
{
if(start %2 == 0)
sum = sum + start;
}

System.out.println(" Sum of Even No in given Range is " + sum);

}
}