The sum of odd numbers

Report a typo

Write a method for calculating the sum of odd numbers in the given interval (inclusively) using Stream API.

Important. Use the provided template for your method. Pay attention to type of an argument and the returned value. Please, don't use loops.

Sample Input 1:

0 0

Sample Output 1:

0

Sample Input 2:

7 9

Sample Output 2:

16

Sample Input 3:

21 30

Sample Output 3:

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

class Main {

/**
* The method calculates the sum of odd numbers in the given range
*
* @param start of a range, start >= 0
* @param end of a range (inclusive), end >= start
*
* @return sum of odd numbers
*/
public static long sumOfOddNumbersInRange(long start, long end) {
// write your code here
}

// Don't change the code below
public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

String[] line = scanner.nextLine().trim().split(" ");

long start = Integer.parseInt(line[0]);
long end = Integer.parseInt(line[1]);

System.out.println(sumOfOddNumbersInRange(start, end));
}
}
___

Create a free account to access the full topic