URI Problem (Sum of Consecutive Odd Numbers II) 1099:
Sum of Consecutive Odd Numbers II is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.
import java.util.Scanner;
/**
* @Author : Muhammad Harun-Or-Roshid
* @Date : Oct 17, 2016
* @Time : 7:44:30 PM
*/
public class Uri1099 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
int x = sc.nextInt();
int y = sc.nextInt();
int count = 0;
if (x > y) {
int temp = x;
x = y;
y = temp;
}
for (int j = (x + 1); j < y; j++) {
if (j % 2 != 0) {
count += j;
}
}
System.out.println(count);
}
}
}
0 Comments