Statistics

Problem Statement for "CountBy"

Problem Statement

PROBLEM STATEMENT:

Class name: CountBy
Method name: countBy
Parameters: int, int, int
Returns: int

Implement a class CountBy, which contains a method countBy.  This method will
return an int that represents the sum of all the numbers from one number
(inclusive) to another number (inclusive) counting by a third number. 

The method signature is:
int countBy(int fromNum, int toNum, int byNum);
Be sure you method is public.

TopCoder will ensure the validity of the inputs. Inputs are valid if all of the
following criteria are met:
*The fromNum will have a value from -500 to 500 inclusive.
*The toNum parameter will have a value from -500 to 500 inclusive.
*The byNum parameter will have a value from 1 to 1001 inclusive.

Notes:
*The toNum parameter can be lower than the fromNum parameter - in which case,
you are counting down by the byNum.

Examples:
-if the input is {10,20,2}, you would count the numbers 10,12,14,16,18,20 and
return their sum 10+12+14+16+18+20 = 90
-if the input is {10,21,2}, you would count the numbers 10,12,14,16,18,20 and
return 90
-if the input is {10,22,2}, you would count the numbers 10,12,14,16,18,20,22
and return 112
-if the input is {10,0,2}, you would count the numbers 10,8,6,4,2,0 and return 30
-if the input is {10,-1,2}, you would count the numbers 10,8,6,4,2,0 and return
30
-if the input is {10,-2,2}, you would count the numbers 10,8,6,4,2,0,-2 and
return 28
-if the input is {10,20,30}, you would return 10
-if the input is {10,10,1}, you would return 10


Definition

Class:
CountBy
Method:
countBy
Parameters:
int, int, int
Returns:
int
Method signature:
int countBy(int param0, int param1, int param2)
(be sure your method is public)

Constraints

    Examples


      This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
      This problem was used for: