Sunday 27 March 2016

Nth Root in Java

Nth Root in Java

















public class NthRt {

  
  public static void main(String[] args){

                int n = args.length;
    
    if(n != 2) {
  
      System.out.println("expected two arguments");
      return;
    }

    double pr = Double.parseDouble(args[0]);
    double pn = Double.parseDouble(args[1]);
    //
    // nth root of a number
    // antilog((1/n)*log(r);
        
        
    double temp = Math.exp((1/pn)*Math.log(pr));

    System.out.println(Math.round(temp));

  

  
  }





}


No comments:

Post a Comment