Search code examples
javalogginglogarithm

How do i calculate 26 + log (base 2)4 in java


26 + log (base 2)4.

How to calculate this in java.

np= (26 + log(2))*4;
System.out.println(np);

I have done this but it is showing garbage value. The answer should be 28.


Solution

  • log (base 2)4 is the same as log10(4)/ log10(2)

    so you can use the java.lang.Math class to calculate that

    System.out.println(26 +Math.log10(4)/Math.log10(2));
    

    the result: 28.0