Hello, I’m working on this task:
Create a class that has one public static method, GetSumBetween, that takes two integers, a and b, and returns as an integer the sum of all integers between a and b (including a and b). In the Main method, read two integers from the console, call GetSumBetween, and print the returned number to the console.
For example (don’t output the green text):
>6
>10
40 // 6 + 7 + 8 + 9 + 10 = 40
Here is my code:
namespace Static
{
class Mine
{
public static int Sum;
public static void GetSumBetween(int a, int b)
{
for (int i=a; i<=b; i++)
{
Mine.Sum = Mine.Sum + i;
}
}
}
class SumThemAll
{
public static void Main()
{
int a = int.Parse(Console.ReadLine());
int b = int.Parse(Console.ReadLine());
Mine.GetSumBetween(a, b);
Console.WriteLine(Mine.Sum);
}
}
}
Can anyone please help me to solve it?