why to use Math.Floor() here?
import java.util.*;
import java.lang.*;
import java.io.*;

class GFG {
static    Scanner scan = new Scanner(System.in);
    public static void main (String[] args) {
        //code
    
    int case1= scan.nextInt();
    GFG g= new GFG();
    g.casein(case1);
    }
    
    public void casein(int case2){
        while(case2-->0){
      
      String s = scan.next();
     
        long height= Long.parseLong(s);
      
        long height2=0;
        
        if(height==0){
            System.out.println(height2);
           
            
        }
        else if(height>0){
           
            height2=height+height;
           while(height>=1){
long fd=2;
               height=(long)height/fd;
       
           height2=(height2 + 2*height);
               
           } 
           
           System.out.println(height2);
           
        }
        else{
        System.out.println(0);
        
        }
        }
         
    }
    
    

Why i have to use Math.Floor() here to get the correct answer because i guess long also get the lowest value like we cant't store 2.5 in long(it will be stored as 2) and Math.floor() also do the same??

Author: dj07
Login to Answer
Sort By:
Oldest
|
Newest
|
Vote
|
My Answer