URI Problem 1099 Solution in Java

Problem Details Link

Solution:



import java.util.Scanner;

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @E-mail : md.parvez28@gmail.com
 * @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);
        }
    }
}

Comments

Post a Comment

Popular posts from this blog

URI Problem 1094 Solution in Java

URI Problem 1012 Solution in Java