Problem 8 [Java]

Back to Problem Solutions forum

MrChebik     2016-04-03 12:31:31
User avatar

Hi, I do not understand, why the server does not consider the right my decision:

import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        int a = scn.nextInt();
        for (int i = 0; i < a; i++) {
            int b = scn.nextInt();
            int c = scn.nextInt();
            int d = scn.nextInt();
            System.out.println(((2*b + c * (d - 1)) / 2) * d + " ");
        }
    }
}

My decision is based on this formula:

advikayya     2018-08-03 03:48:13

Use floats when dividing and then cast the final answer to an int.

Please login and solve 5 problems to be able to post at forum