Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. public class Logarithmus {
  2.     public static void main(String[] args) {
  3.        
  4.         double ln2 = 0.0d;
  5.         double counter = 1d;
  6.         boolean check = false;
  7.        
  8.         for (double i = 1; i <= 1000000; i++) {
  9.            
  10.             if (i % 2 == 1) {
  11.                
  12.                 ln2 -= 1d - (1 / i);
  13.                
  14.             } else {
  15.                
  16.                 ln2 += 1d - (1 / i);
  17.                
  18.             }
  19.            
  20.             if ((ln2 - Math.log(2) <= 0.0023 && ln2 - Math.log(2) >= 0) ||
  21.             (Math.log(2) - ln2 <= 0.0023 && Math.log(2) - ln2 >= 0)){
  22.                
  23.                 check = true;
  24.                 counter++;
  25.             }
  26.            
  27.            
  28.            
  29.         }
  30.        
  31.         System.out.println(counter);
  32.        
  33.         /*
  34.         for (double j = ln2; j < Math.log(2); j++) {
  35.            
  36.             summanden++;
  37.             System.out.println("Abweichung des Ergebnis vom echten Wert um " + summanden + " Stellen.");
  38.  
  39.         }
  40.        
  41.         /*if (Math.log(2) == ln2) {
  42.            
  43.             summanden++;   
  44.             System.out.println("Abweichung des Ergebnis vom echten Wert um " + summanden + " Stellen.");
  45.  
  46.         } */
  47.        
  48.         System.out.println("Mit der Formel ln2 = " + ln2);
  49.         System.out.println("Probe: Math.log(2) = " + Math.log(2)); 
  50.        
  51.     }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement