Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 KB | None | 0 0
  1. public class Logarithmus {
  2.     public static void main(String[] args) {
  3.        
  4.         double ln2 = 1d;
  5.         int counter = 1;
  6.         boolean pruef = false;
  7.         double difference = 10000;
  8.        
  9.         while(difference > 0.0023) {
  10.             counter++;
  11.             if (counter % 2 == 1) {
  12.                
  13.                 ln2 -= 1d - 1 / (float)counter;
  14.                 //ln2 = ln2 + 1 / (float)counter;
  15.                
  16.             }else {
  17.                
  18.                 ln2 += 1d - 1 / (float)counter;
  19.                 //ln2 = ln2 - 1 / (float)counter;
  20.                
  21.             }
  22.            
  23.            
  24.             difference = Math.log(2) - ln2;
  25. if(difference < 0)
  26.  difference *= -1;
  27.  
  28.            
  29.         }
  30.        
  31.         System.out.println("Mit der Formel ln2 = " + ln2);
  32.         System.out.println("Probe: Math.log(2) = " + Math.log(2));
  33.         System.out.println("Abweichung des Ergebnis vom echten Wert um " + counter + " Stellen.");
  34.        
  35.     }
  36.    
  37.    
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement