How to get the natural logarithm of a number in Java

1 Answer

0 votes
package javaapplication1;

public class JavaApplication1 {
 
    public static void main(String[] args) {
        
        double d1 = 3.14;
        double d2 = 7.899;

        System.out.printf("log(%.3f) = %.3f%n", d1, Math.log(d1));
        System.out.printf("log(%.3f) = %.3f%n", d2, Math.log(d2));
    }
}
 
/*
run:

log(3.140) = 1.144
log(7.899) = 2.067
 
*/

 



answered Sep 8, 2016 by avibootz
...