Problem 8 [Java]

Back to General discussions forum

MrChebik     2016-04-02 20:30:58
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:

bobmarleyvodka     2017-03-14 13:56:07

Hi! Don't think it is useful for you now, one year later, but might be useful for someone else. I've faced same problem while solving this task, so I've checked the output data with a calc. The thing is that variable for output data must be declared as double type, not integer. And then only a final result must be casted to the integer type)

annekorti     2018-02-07 21:59:00

Scanner in = new Scanner(System.in);

    System.out.println("Введите кол-во сравниваемых чисел: ");
    int n = in.nextInt();

    for (int i = 0; i < n+1; i++) {
      int a = in.nextInt();
      int b = in.nextInt();
      int c = in.nextInt();

        int an = a+b*(c-1);
        int sn = (((a+an)*c)/2);
      System.out.println(sn);
      }
Please login and solve 5 problems to be able to post at forum