Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /**
- Computes a sum of odd integers between two bounds.
- Input: a, the lower bound (may be odd or even).
- Input: b, the upper bound (may be odd or even).
- Output: sum of odd integers between a and b (inclusive).
- */
- public class OddSum
- {
- public static void main(String[] args)
- {
- // Read values for a and b
- Scanner in = new Scanner(System.in);
- int a = in.nextInt();
- int b = in.nextInt();
- int sum = 0;
- for(;a <= b; a++)
- {
- if(a % 2 != 0){sum += a;}
- }
- System.out.println(sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement