Answer the question
In order to leave comments, you need to log in
Why is the variable written incorrectly??
I need help, I can't understand where the number 2 comes from in my code, I checked everything everything works correctly, but these two come from nowhere!!! Help!
The answer should be 4 in advance, but the code returns 8!!
I understand that the code is not written beautifully, but the point is that in order to solve the problem Here is the code:
package testone;
import java.math.*;
import java.util.Scanner;
public class TestOne
{
BigDecimal s;
BigDecimal f;
BigDecimal h;
BigDecimal y;
public BigDecimal ceil (int a, int b)
{
s = BigDecimal.valueOf(a);
h = BigDecimal.valueOf(b);
y = BigDecimal.valueOf(1);
//return ((a+b-1)/b);
f = ((s.add(h).subtract(y)).divide(h,BigDecimal.ROUND_HALF_DOWN));
System.out.println(" ceil ---" + f);
return f;
}
public BigDecimal getRezult(int m, int n, int a)
{
h = ceil(m , a);
System.out.println("hhhhhh ---" + h);
y = ceil(n , a);
System.out.println("yyyyyyyyyyyy ---" + h);
System.out.println("h.multiply(y) -----" + h.multiply(y));
return h.multiply(y);
//return ceil(m , a) * ceil(n , a);
}
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int m = scan.nextInt();
int a = scan.nextInt();
TestOne z = new TestOne();
System.out.println(z.getRezult(m, n, a));
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question