Advertisement
cardel

MDIIEjemplo3-14Dic

Dec 14th, 2020
941
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1.  
  2.  
  3. class Main {
  4.  
  5.   static double recursivo(int n){
  6.     if(n==0){
  7.       return 4.0;
  8.     }
  9.     else{
  10.       if(n==1){
  11.         return 6.0;
  12.       }
  13.       else{
  14.         return 5.0*recursivo(n-1)-4.0*recursivo(n-2);
  15.       }
  16.     }
  17.  
  18.   }
  19.  
  20.   static double formula(int n){
  21.  
  22.     double A = 2.0/3.0;
  23.     double B = 10.0/3.0;
  24.     double r1 = Math.pow(4,n);
  25.  
  26.     return A*r1+B;
  27.  
  28.   }
  29.  
  30.   public static void main(String[] args) {
  31.     for(int i=0;i<20;i++){
  32.       String salida=" n "+String.valueOf(i);
  33.      
  34.       String salidaA = " recursiva "+recursivo(i);
  35.  
  36.       String salidaB = " fórmula "+formula(i);
  37.  
  38.       salida+=salidaA;
  39.       salida+=salidaB;
  40.  
  41.       System.out.println(salida);
  42.     }
  43.    
  44.   }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement