Advertisement
advictoriam

Untitled

Jan 8th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /**
  4.    Computes a sum of odd integers between two bounds.
  5.    Input: a, the lower bound (may be odd or even).
  6.    Input: b, the upper bound (may be odd or even).
  7.    Output: sum of odd integers between a and b (inclusive).
  8. */
  9. public class OddSum
  10. {
  11.    public static void main(String[] args)
  12.    {
  13.       // Read values for a and b
  14.       Scanner in = new Scanner(System.in);
  15.       int a = in.nextInt();
  16.       int b = in.nextInt();
  17.      
  18.       int sum = 0;
  19.       for(;a <= b; a++)
  20.       {
  21.          if(a % 2 != 0){sum += a;}
  22.       }
  23.      
  24.       System.out.println(sum);
  25.    }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement