Guest User

Untitled

a guest
Apr 19th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class horner {
  3.    
  4.     public static double horner(double a, double x, int n){
  5.         Scanner bucky = new Scanner(System.in);
  6.         double h;
  7.         if(n>0){
  8.             System.out.println("(a"+(n-1)+ ") eingeben");
  9.             double b = bucky.nextDouble();
  10.             double z = a*x+b;
  11.             h=horner(z, x, n-1);
  12.         }else{
  13.             return a;
  14.         }
  15.         return h;
  16.       }
  17.  
  18.     public static void main(String[] args) {
  19.         Scanner bucky = new Scanner(System.in);
  20.         System.out.println("Grad der Funktion eingeben");
  21.         int n = bucky.nextInt();           
  22.         System.out.println("X-Wert eingeben");
  23.         double x = bucky.nextDouble();
  24.         System.out.println("(a"+n+") eingeben");
  25.         double an =bucky.nextDouble();
  26.         double wert = horner(an, x, n);
  27.         System.out.println("Ergebnis = "+wert);
  28.     }
  29.  
  30. }
Add Comment
Please, Sign In to add comment