Merge pull request #5307 from grigoriosdimopoulos/BAEL2150
[BAEL2150] Nth root in Java
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
package com.baeldung.nth.root.calculator;
|
||||
|
||||
public class NthRootCalculator
|
||||
{
|
||||
public Double calculate(Double base, Double n) {
|
||||
return Math.pow(Math.E, Math.log(base)/n);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.baeldung.nth.root.main;
|
||||
|
||||
import com.baeldung.nth.root.calculator.NthRootCalculator;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
NthRootCalculator calculator = new NthRootCalculator();
|
||||
Double base = Double.parseDouble(args[0]);
|
||||
Double n = Double.parseDouble(args[1]);
|
||||
Double result = calculator.calculate(base, n);
|
||||
System.out.println("The " + n + " root of " + base + " equals to " + result + ".");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user