Implement a method sumInRange for calculating the sum of numbers in the range from (inclusive), to (exclusive). Mind the type of the return value.
Declaring methods
Sum of numbers in the range
Report a typo
Sample Input 1:
1 2Sample Output 1:
1Sample Input 2:
5 5Sample Output 2:
0Sample Input 3:
10 15Sample Output 3:
60Write 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));
}
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.