Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class horner {
- public static double horner(double a, double x, int n){
- Scanner bucky = new Scanner(System.in);
- double h;
- if(n>0){
- System.out.println("(a"+(n-1)+ ") eingeben");
- double b = bucky.nextDouble();
- double z = a*x+b;
- h=horner(z, x, n-1);
- }else{
- return a;
- }
- return h;
- }
- public static void main(String[] args) {
- Scanner bucky = new Scanner(System.in);
- System.out.println("Grad der Funktion eingeben");
- int n = bucky.nextInt();
- System.out.println("X-Wert eingeben");
- double x = bucky.nextDouble();
- System.out.println("(a"+n+") eingeben");
- double an =bucky.nextDouble();
- double wert = horner(an, x, n);
- System.out.println("Ergebnis = "+wert);
- }
- }
Add Comment
Please, Sign In to add comment