Hi im extremly new to programming, and this is a school project i need help with.
I'm supposed to take an input from the user and calculate the value of pi using this formula: 1/1 - 1/3 + 1/5 - 1/7 etc... so on alternating between minus and plus and denominator increasing by 2 every time. If the user inputs the number 3, then it should print (1/1 - 1/3 + 1/5 - 1/7 + 1/9) *4. The idea here is that the higher the input of the user is, the higher the equation will be close to pi.
this is what i have so far, i know its pitififul /
import java.util.Scanner;
public class Pi
{
public static void main(String[] args)
{
double first = 1/1;
double second = 1/3;
Scanner input = new Scanner(System.in);
System.out.println("Enter a Number to calculate how far you want the formula to perform: ");
double count = input.nextDouble();
}
}
this is literally all i have, i know i need a while loop and an if loop. any help?