The code below will not execute with some inputs

Sorry for such a basic question. But I'm starting to program. Not a computer guy. So kindly help me. In this code, when I give input 1000000000, 1000000000, 999999999the answer should be 4. But my answer is 1. I expect that the operator ifwill be executed, but he is not satisfied here.

if you take m * n as a room and "a" as a square tile. Then I want to take MINIMUM no. from tiles it is necessary to fill the floor of the room. the tile may cover a little more area, but should not leave the room empty. it is my goal. It works with inputs like 6,6,4 or 15,20,13 etc.

Now its working guys. I posted the correct code with these minor changes below.

import java.util.Scanner;
public class TheatreSquare {
    private static Scanner input;
     public static void main(String[] args) {
     input = new Scanner(System.in);
     float m=input.nextFloat();
     float n=input.nextFloat();
     float a=input.nextFloat();
     long i=(int)(m/a);
     long j=(int)(n/a);

     if((a*a*i*j)<m*n){

        if(a*i<m){
            //to check weather it is entering if()
            System.out.println("true");
            i+=1;
        }
        if(a*j<n){
            System.out.println("false");
            //to check weather it is entering if()
            j+=1;
        }
       }
       System.out.println((double)(i*j));
     }
 }
+4
4

. m, n a double :

double m = input.nextDouble();
double n = input.nextDouble();
double a = input.nextDouble();
+3

int .

a*a*i*j m*n , if . a*i m, a*j n. , isi j 1, i*j 1. Look at this

, .

if((a*a*i*j)<m*n){

        if(a*i<m){
            //to check weather it is entering if()
            System.out.println("true");
            i+=1;
        }
        if(a*j<n){
            System.out.println("false");
            //to check weather it is entering if()
            j+=1;
        }
       }

if((a*a*i*j) <= m*n){
        System.out.println("Entered if block");
        if(a*i <= m){
            //to check weather it is entering if()
            System.out.println("true");
            i+=1;
        }
        if(a*j <= n ){
            System.out.println("false");
            //to check weather it is entering if()
            j+=1;
        }
        System.out.println("i is:"+ i +"j is:"+j);
       }
+2

thankyou @Mureinik, @Uma Lakshmi Kanth, @Diego Martinoia . . . @Mureinik , ( ). Double float . .: -)

import java.util.Scanner;
public class TheatreSquare {
private static Scanner input;
public static void main(String[] args) {
    input = new Scanner(System.in);
    double m=input.nextDouble();
    double n=input.nextDouble();
    double a=input.nextDouble();
    long i=(long)(m/a);
    long j=(long)(n/a);

    if((a*a*i*j) <m*n){
        if(a*i < m){
            //to check weather it is entering if()
            i+=1;
        }
        if(a*j < n ){
            //to check weather it is entering if()
            j+=1;
        }
       }
    System.out.println((long)(i*j));
}
}
+2

, . , m n a ( ). ( ) . , , , !

--- ---

m n . 1 , .. ( ).

, , :

Math.ceiling((m*n) / (a*a));

those. either your area is an exact multiple of your fragments (and you can always cut them in rectangles to fit the shape of the room), or you will have some kind of “spare” space to fill, so you will need 1 more tile, part which you will use to cover the remaining space, and the part that you throw away.

+1
source

All Articles