[ruby] gfg

Viewer

  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class GFG {
  6. static    Scanner scan = new Scanner(System.in);
  7.     public static void main (String[] args) {
  8.         //code
  9.     
  10.     int case1= scan.nextInt();
  11.     GFG g= new GFG();
  12.     g.casein(case1);
  13.     }
  14.     
  15.     public void casein(int case2){
  16.         while(case2-->0){
  17.       
  18.       String s = scan.next();
  19.      
  20.         long height= Long.parseLong(s);
  21.       
  22.         long height2=0;
  23.         
  24.         if(height==0){
  25.             System.out.println(height2);
  26.            
  27.             
  28.         }
  29.         else if(height>0){
  30.            
  31.             height2=height+height;
  32.            while(height>=1){
  33. long fd=2;
  34.                height=(long)height/fd;
  35.        
  36.            height2=(height2 + 2*height);
  37.                
  38.            } 
  39.            
  40.            System.out.println(height2);
  41.            
  42.         }
  43.         else{
  44.         System.out.println(0);
  45.         
  46.         }
  47.         }
  48.          
  49.     }
  50.     
  51.     
  52.  
  53. 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??

Editor

You can edit this paste and save as new:


File Description
  • gfg
  • Paste Code
  • 01 Feb-2018
  • 1.19 Kb
You can Share it: