hi
this is the URL link of the code
http://www.beta.browxy.com#USER_157857
any idea of to write the method for log2(n)?
thanks
how to writh method of log
-
- Posts: 63
- Joined: Sun Jan 07, 2018 6:30 pm
Re: how to writh method of log
Hi!
To use logarithm you need to import the Math class and use the method log
To use logarithm you need to import the Math class and use the method log
Code: Select all
import java.lang.Math;
public class Calc {
public static void main(String[] args){
System.out.println (calc(16));
}
public static double calc (int n) {
if(n <=2 )
return 1 ;
return (calc(n/2) * Math.log(n));
}
}
-
- Posts: 32
- Joined: Thu Dec 21, 2017 10:06 pm
Re: how to writh method of log
hi,
getting an error
symbol: method log2(int)
location: class java.lang.Math
also,i need the log to be with base 2
is ther a way to writhe the method log without importint the class math ?
getting an error
symbol: method log2(int)
location: class java.lang.Math
also,i need the log to be with base 2
is ther a way to writhe the method log without importint the class math ?
-
- Posts: 63
- Joined: Sun Jan 07, 2018 6:30 pm
Re: how to writh method of log
Hi!
The log2 method is not a valid method from the Math class. Also there is no log2 method in the standard java JDK.
To have a log2 functionality you should do something like this:
Math.log(x)/Math.log(2)
See: http://www.giannistsakiris.com/2010/01/ ... n-in-java/
The log2 method is not a valid method from the Math class. Also there is no log2 method in the standard java JDK.
To have a log2 functionality you should do something like this:
Math.log(x)/Math.log(2)
See: http://www.giannistsakiris.com/2010/01/ ... n-in-java/
-
- Posts: 32
- Joined: Thu Dec 21, 2017 10:06 pm
Re: how to writh method of log
Thanks a lot 
