vercel / next.js

The React Framework
https://nextjs.org
MIT License
125.96k stars 26.87k forks source link

help in calculating the value of pi up to 1000 terms #170

Closed M8l closed 7 years ago

M8l commented 7 years ago

hi people ,

I can't find what's going wrong with my code here ; it should works this way when the user enter any multiple term of 100 up to 1000 the output should be the value of pi up to that term ; but the problem is when the user enter 200 it outputs 2 values of 200 instead of one and the same when the user enter 300 , it outputs 3 values !

here is the question and my code ;

The value for π can be calculated from the infinite series: π=4-4/3+4/5-4/7+4/9-4/11+ ⋯ Write a program that prints the approximate value of π after 10000 terms of this series. Your program should also display a table that shows the value of π after terms that are multiples of 100, i.e., it should show π values at 100, 200, 300, …, 10000 terms.

package idk;
import java.util.Scanner;

public class pi {
public static void main (String[]args){
    Scanner kb = new Scanner (System.in);
    double sum = 0;
    System.out.print(" Enter one multiple of 100 up to 1000 ");
    int r = kb.nextInt();
    for (int i=1 ; i<=r ; i++){
        double piformula = Math.pow(-1,i+1 )*4/(2*i-1) ;
        sum+=piformula ;

        if(i%100==0)

            System.out.println("the value of pi after " + r + " terms is " + sum);

}
}

}
M8l commented 7 years ago

I'm sorry , I know there are many language mistakes , and I don't know if this is the right place to post my issue

kenneth1974 commented 7 years ago

https://adobeid-na1.services.adobe.com/renga-idprovider/pages/start_forgot_password?client_id=ReaderMobileWindowsPhone81_0001&display=web_v2&callback=https://ims-na1.adobelogin.com/ims/adobeid/ReaderMobileWindowsPhone81_0001/AdobeID/device?redirect_uri=http%3A%2F%2Freadermobile.acrobat.com%2Fpath%2F&state=%7B%22ac%22%3A%22ReaderMobileWin81%3ALogin%22%2C%22av%22%3A%2216%2C0%22%2C%22di%22%3Anull%2C%22mc%22%3Anull%2C%22pl%22%3Anull%7D&device_id=ezUAnKo6boGq6VG2tFDuQbsP8cxyCBtyYySaNlQLCH8%3D&scope=AdobeID%2Copenid%2Cskybox&denied_callback=https://ims-na1.adobelogin.com/ims/denied/ReaderMobileWindowsPhone81_0001?redirect_uri=http%3A%2F%2Freadermobile.acrobat.com%2Fpath%2F&response_type=device&state=%7B%22ac%22%3A%22ReaderMobileWin81%3ALogin%22%2C%22av%22%3A%2216%2C0%22%2C%22di%22%3Anull%2C%22mc%22%3Anull%2C%22pl%22%3Anull%7D&scope=AdobeID%2Copenid%2Cskybox&locale=en_US&username=&internal_browser=true

-----Original Message----- From: "M8l" notifications@github.com Sent: ‎10/‎31/‎2016 12:40 To: "zeit/next.js" next.js@noreply.github.com Subject: Re: [zeit/next.js] help in calculating the value of pi up to 1000terms (#170)

I'm sorry , I know there are many language mistakes , and I don't know if this is the right place to post my issue — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.