SHARE
TWEET

Untitled

advictoriam Jan 8th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top