Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Logarithmus {
- public static void main(String[] args) {
- double ln2 = 1d;
- int counter = 1;
- boolean pruef = false;
- double difference = 10000;
- while(difference > 0.0023) {
- counter++;
- if (counter % 2 == 1) {
- ln2 -= 1d - 1 / (float)counter;
- //ln2 = ln2 + 1 / (float)counter;
- }else {
- ln2 += 1d - 1 / (float)counter;
- //ln2 = ln2 - 1 / (float)counter;
- }
- difference = Math.log(2) - ln2;
- if(difference < 0)
- difference *= -1;
- }
- System.out.println("Mit der Formel ln2 = " + ln2);
- System.out.println("Probe: Math.log(2) = " + Math.log(2));
- System.out.println("Abweichung des Ergebnis vom echten Wert um " + counter + " Stellen.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement