Sum of numbers in the range

Report a typo

Implement a method sumInRange for calculating the sum of numbers in the range from (inclusive), to (exclusive). Mind the type of the return value.

Sample Input 1:

1 2

Sample Output 1:

1

Sample Input 2:

5 5

Sample Output 2:

0

Sample Input 3:

10 15

Sample Output 3:

60
Write a program in Java 17
import java.util.Scanner;

public class Main {

/**
* The method calculates the sum of integers in a given range
*
* @param from inclusive
* @param to exclusive
*
* @return the sum (long)
*/
public static long sumInRange(int from, int to) {
// write your code here
}

/* Do not change code below */
public static void main(String[] args) {
final Scanner scanner = new Scanner(System.in);

int from = scanner.nextInt();
int to = scanner.nextInt();

System.out.println(sumInRange(from, to));
}
}
___

Create a free account to access the full topic