pi - My Java program isn't changing value of variable -


i learning java , decided create pi calculator, wrote in python , got working 14 d.p.

the formula i'm using works calculating decimal part in infinite loop , adding 3 onto it.

however i've brought java, doesn't see change the 'total' variable beyond '3.0' (this problem). know because can see code below displays total after every loop.

here code:

public class divider {     public static void main(string[] args) {         //declares variables         boolean posorneg = true;         double total = 3.0;         long count = 0;         long no1 = 0;         long no2 = 1;         long no3 = 2;         double changer = 0;          /begins loop         {             // sets value total value changed             no1 =+ 2;             no2 =+ 2;             no3 =+ 2;             changer = (4 / (no1 * no2 * no3));              if (posorneg == true) {                 total = total + changer;                 posorneg = false;             } else {                 total = total - changer;                 posorneg = true;             }              count += 1;             system.out.println(total);         } while (count != 31957);          // displays total calculated , how many loops reaching value required         system.out.println("pi");         system.out.println(total);         system.out.println(count);     } } 

any appreciated

assign variable

double sum = 4; 

change

 no1 = +2;  no1 +=2; or no1 = no1+2;  no2 = +2;   no2 +=2; or no2 = no2+2;  no3 = +2;  no3 +=2; or no3 = no3+2; 

change

 changer = (4/ (no1 * no2 * no3));  changer = (sum/ (no1 * no2 * no3)); 

it work.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -